dotnet / dotnet/project-system

Put TargetFramework in VersionSuffix cause Visual Studio build fail

Open
#9,027 0 comments 0 reactions 0 assignees View on GitHub
Feature-NuGet Triage-Investigate
Dominant language
C#
Stars
1k
Forks
415
PR merge metrics
No merged PRs in 30d

Description

_This issue has a corresponding [ticket on Developer Community](https://developercommunity.visualstudio.com/t/Put-TargetFramework-in-VersionSuffix-cau/1601421). 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.

```xml


Exe
net35;net40
1.2.3
$(TargetFramework)

```

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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.