Msbuild and VStudio generate different project.assets.json files

Viewed 215

This question is about the differences in the content of the NET 5 project.assets.json file when Visual Studio or Msbuild generate the file. My experiments have shown the following findings:

  • VStudio regenerates the project.assets.json file on each ‘clean’ operation.

  • VStudio creates only a target net5.0-windows7.0 in the json file.

  • VStudio can build and debug the project within only net5.0-windows7.0 in the json file.

  • VStudio does not create a target net5.0-windows7.0/win-x64 in the json file.

  • Msbuild requires a target net5.0-windows7.0/win-x64 for a successful build.

  • MsBuild will not regenerate the project.assets.json file if it exists.

  • Msbuild fails on a VS-generated project.assets.json file.

The only way I can get a successful build with msbuild is to delete the obj/project.assets.json file and let msbuild regenerate it (probably with a restore operation). When msbuild regenerates the json file, it includes BOTH targets for net5.0-windows7.0 and net5.0-windows7.0/win-x64.

I have experimented with various combinations and permutations of Platform=x64/AnyCPU, PlatformTarget=x64/AnyCPU, and RuntimeIdentifier=win-x64 in the csproj file, but without success. The only way I can get a successful msbuild on the command line is to delete all existing project.asset.json files for all projects involved in the build.

Here is my msbuild command line:

msbuild  /t:clean;restore;publish /p:Platform=AnyCPU /p:PlatformTarget=AnyCPU /p:Configuration=Debug /p:TargetFramework=net5.0-windows7.0  /p:RuntimeIdentifier=win-x64 /p:SelfContained=false /p:PublishProtcol=FileSystem /p:DeleteExistingFiles=true MyFile.csproj

Here is my csproj file (I added RuntimeIdentifer=win-x64 and Platforms/Target=AnyCPU;x64 in the permutations, but they did not help.)

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <Platforms>AnyCPU</Platforms>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup>

Here is the Project.assets.json file generated by VStudio:

{
  "version": 3,
  "targets": {
    "net5.0-windows7.0": {}
  },
. . . no runtimes section in the VStudio-generated file

Here is the Project.assets.json generated by MsBuild:

{
  "version": 3,
  "targets": {
    "net5.0-windows7.0": {},
    "net5.0-windows7.0/win-x64": {}
  },
. . . 
  "runtimes": {
      "win-x64": {
        "#import": []
      }
    }

Q. Is this normal behavior for VS and msbuild?

Q. Why doesn’t msbuild /t:clean;restore;publish automatically regenerate the file using the arguments on the msbuild command line? If VS can automatically regenerate the file on a clean operation, why won’t msbuild do the same thing?

Q. Am I doing something wrong, or is there a way to avoid deleting the project.asset.json files before every msbuild operation?

0 Answers
Related