1 year ago

#333365

test-img

Moe Sisko

Determining/controlling which version of a referenced Multi target (.net standard and .net framework) library gets used within same solution?

Example, using Visual Studio 2019 on Windows 10:

Created a class library ("MyLib1") targeting both .net standard and .net 4.7.2 .
Part of the csproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>  
    <TargetFrameworks>netstandard2.0;net472</TargetFrameworks>

When this library is built, it creates two versions of the dll. The .net standard one under subdirectory: bin\Debug\netstandard2.0 , and the .net framework one under: bin\Debug\net472 . (All good so far).

In the same solution, there is a winforms application project (targeting .net 4.7.2). This references the class library. This project uses the old style csproj (not sdk style). Part of csproj file looks like this:

  <ItemGroup>
    <ProjectReference Include="..\MyLib1\MyLib1.csproj">
      <Project>{some guid here}</Project>
      <Name>MyLib1</Name>
    </ProjectReference>
  </ItemGroup>

In Visual Studio, When I build and run the app, it seems that the .net framework version of MyLib1 gets copied to the bin\Debug directory of the app (This can be seen using ilspy).

Question 1: What are the rules for determining which version of the library gets used?

Question 2: Is it possible to control which version of the library gets used by the winforms app ? e.g. maybe there is a way to do it via some setting in the csproj file.

In case you are wondering: multitarget is required for the library, because the library also needs to be used in SQLCLR, which does not support loading of .net standard assemblies. But when the library is used outside of SQLCLR, I would prefer that the .net standard version of it is used.

.net

visual-studio

.net-standard

0 Answers

Your Answer

Accepted video resources