project-system icon indicating copy to clipboard operation
project-system copied to clipboard

Put TargetFramework in VersionSuffix cause Visual Studio build fail

Open vsfeedback opened this issue 2 years ago • 0 comments

This issue has a corresponding ticket on Developer Community. Please vote and comment there to make sure your voice is heard.


Install .NET SDK 6.0.100 Create C# SDK-style project. Set TargetFrameworks property to multiple frameworks (at least 2 frameworks, such as net35;net40 or net50;netcoreapp3.1). Set VersionSuffix property to $(TargetFramework) so that EXE product versions become 1.2.3-net35 / 1.2.3-net40. Build the project in Visual Studio 2022 or 2019 and error occurred about NuGet package restore. No such error if build with dotnet command line directly.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net35;net40</TargetFrameworks>
    <VersionPrefix>1.2.3</VersionPrefix>
    <VersionSuffix>$(TargetFramework)</VersionSuffix>
  </PropertyGroup>
</Project>

Build the project in Visual Studio 2022 or 2019.

Rebuild started...
1>------ Rebuild All started: Project: ConsoleApp1, Configuration: Debug Any CPU ------
Failed to restore C:\ConsoleApp1\ConsoleApp1.csproj (in 1 ms).
NuGet package restore failed. Please see Error List window for detailed warnings and errors.
1>C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\ConsoleApp1\obj\project.assets.json' doesn't have a target for 'net35'. Ensure that restore has run and that you have included 'net35' in the TargetFrameworks for your project.
1>Done building project "ConsoleApp1.csproj" -- FAILED.
1>C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1005: Assets file 'C:\ConsoleApp1\obj\project.assets.json' doesn't have a target for 'net40'. Ensure that restore has run and that you have included 'net40' in the TargetFrameworks for your project.
1>Done building project "ConsoleApp1.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Delete bin and obj directories and build with command line. No error if build with dotnet command line directly.

C:\ConsoleApp1>dotnet build
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored C:\ConsoleApp1\ConsoleApp1.csproj (in 229 ms).
  ConsoleApp17 -> C:\ConsoleApp1\bin\Debug\net35\ConsoleApp1.exe
  ConsoleApp17 -> C:\ConsoleApp1\bin\Debug\net40\ConsoleApp1.exe

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.15

vsfeedback avatar May 18 '23 00:05 vsfeedback