Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Different nuget-packages loaded when using MSBuild than building using Visual Studio

$
0
0

I also posted this question on the microsoft forums:https://docs.microsoft.com/en-us/answers/questions/249621/different-nuget-packages-are-used-when-compiling-u.html

Consider following .csproj file:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"><PropertyGroup><OutputType>WinExe</OutputType><TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks><UseWPF>true</UseWPF></PropertyGroup><ItemGroup><PackageReference Include="Newtonsoft.Json" Version="12.0.3" Condition="'$(TargetFramework)' == 'net5.0-windows'"/><PackageReference Include="Newtonsoft.Json" Version="11.0.1" /></ItemGroup></Project>

Except for the files generated by visual studio when creating the project, there are no other files in this project. The generated files (except the .csproj file) are not altered in any way.

enter image description here

As you can see in the image, visual studio will - for both projects - reference the 11.0.1 version, and also build the executables using the 11.0.1 version.

When using the Command Line with MSBuild

<msbuildpath> <projectpath> /restore

The executables will be generated with the 12.0.3 version for the .net5.0 target and with the 11.0.1 version for the other target(s)

When using nuget.exe /restore from the command line it will also generate the assets file to use 12.0.3 for .net5.0 and 11.0.1 for the other targets.

Why is there a difference between the packages using visual studio and nuget/msbuild?Is this expected behavior or is this a bug?

*As a side note, the problem does fix itself when using choose/when tags

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"><PropertyGroup><OutputType>WinExe</OutputType><TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks><UseWPF>true</UseWPF></PropertyGroup><Choose><When Condition="'$(TargetFramework)' == 'net5.0-windows'"><ItemGroup><PackageReference Include="Newtonsoft.Json" Version="12.0.2" /></ItemGroup></When><Otherwise><ItemGroup><PackageReference Include="Newtonsoft.Json" Version="11.0.1" /></ItemGroup></Otherwise></Choose></Project>
  • No matter which build-method generates the correct output, i would expect for MSBuild and VS to generate the same output. Or am i wrong?
  • Why is there a difference between the packages using visual studio and nuget/msbuild?
  • Is this expected behavior or is this a bug?

Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>