Skip to content

VS: DOTNET_SDK skips VS_DOTNET_REFERENCE_<refname>

Here's a sample CMakeLists.txt, running 3.22.20220130-ga1f5e268.

cmake_minimum_required(VERSION 3.22.0) # Need CMake 3.22 nightly

project(testproject LANGUAGES CSharp)

include(CSharpUtilities)

add_executable(HelloWorld "HelloWorld.cs")

set_target_properties(HelloWorld PROPERTIES
    DOTNET_TARGET_FRAMEWORK_VERSION "4.7.2"

    VS_DOTNET_REFERENCE_SomeDll
        ${PROJECT_SOURCE_DIR}/SomeDll.dll
)

This works. I see the following block in HelloWorld.csproj:

  <ItemGroup>
    <Reference Include="SomeDll">
      <CopyLocalSatelliteAssemblies>true</CopyLocalSatelliteAssemblies>
      <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
      <Private>True</Private>
      <HintPath>D:\src\test\SomeDll.dll</HintPath>
    </Reference>
  </ItemGroup>

Now let's switch the CMakeLists.txt to use DOTNET_SDK instead:

cmake_minimum_required(VERSION 3.22.0) # Need CMake 3.22 nightly

project(testproject LANGUAGES CSharp)

include(CSharpUtilities)

add_executable(HelloWorld "HelloWorld.cs")

set_target_properties(HelloWorld PROPERTIES
    DOTNET_SDK "Microsoft.NET.Sdk"
    DOTNET_TARGET_FRAMEWORK "net472"

    VS_DOTNET_REFERENCE_SomeDll
        ${PROJECT_SOURCE_DIR}/SomeDll.dll
)

Here's the generated .csproj. No reference to SomeDll.dll at all:


<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup Label="Globals">
    <ProjectGuid>{830F543F-6CA4-334B-A6AF-DD7F74128D60}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <EnableDefaultItems>false</EnableDefaultItems>
    <VCProjectUpgraderObjectName>NoUpgrade</VCProjectUpgraderObjectName>
    <ManagedAssembly>true</ManagedAssembly>
    <TargetFramework>net472</TargetFramework>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="D:\src\test\HelloWorld.cs">
      <Link>HelloWorld.cs</Link>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="D:\src\test\_build\ZERO_CHECK.vcxproj">
      <Project>{5CC0DD8F-7421-34B1-895D-419276575F16}</Project>
      <Name>ZERO_CHECK</Name>
      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </ProjectReference>
  </ItemGroup>
</Project>

I tried target_link_libraries with the path to the DLL but that didn't work either.

VS_PACKAGE_REFERENCES works perfectly, but I can't find a way to reference a pre-compiled .dll I have on disk with DOTNET_SDK.

Edited by Brad King
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information