Building .NET Framework projects with "dotnet build" does not work
Starkie opened this issue · comments
While trying to build a project that uses StrongNamer with we found the following error:
D:\Packages\strongnamer\0.2.5\build\StrongNamer.targets(21,5): error : StrongNamer requires at least the .NET Core SDK v2.1 to run with 'dotnet build'
This was a bit weird, since we are on NET Core 3.1.100 sdk
. So, I did some digging on the strongnamer.targets
file, I found out what might be the culprit:
strongnamer/src/StrongNamer/StrongNamer.targets
Lines 10 to 11 in 5c3e0dc
The variable BundledNETCoreAppTargetFrameworkVersion
is used to determine the value of StrongNamerNetCoreAppVersion
. If it can't be resolved, the value 1.0 will be used instead. This makes the following validation fail:
strongnamer/src/StrongNamer/StrongNamer.targets
Lines 21 to 24 in 5c3e0dc
Should this variable reference be replaced?
EDIT: Removed reference to a pull request from dotnet/sdk repository, since it wasn't actually related.
Ok, so I did even more digging:
The problem actually is that one of my solutions has only a .NET 4.7.2 project, with the old project style.
I am building the solution with the dotnet build
command, which should work.
When the compilation reaches the target:
- The
BundledNETCoreAppTargetFrameworkVersion
tagets has no value. It has not been imported since the dotnet core sdk wasn't either.StrongNamerMinCoreVersionRequired
is assigned the value1.0
. - Since I'm using
dotnet build
instead of msbuild directly,MSBuildRuntimeType
has the valueCore
. - Since both conditions are true, the error condition is triggered.
What could be a way to allow .NET full projects to be built with dotnet build
?
Well, it seems the issue was on our side. Sorry about that 😅
In case anyone stumbles on a similar problem, for reference: The issue is that one of the projects was on the old .NET Framework SDK style. Which is not supported by dotnet CLI.
Regarding the missing variable, BundledNETCoreAppTargetFrameworkVersion
: it comes from (a few nested imports inside) the Microsoft.NET.Sdk
. This reference was not present on the old-style projects, so it could not be resolved. Leading to the error described in the first comment.
So... to solve it: we are going to migrate those projects to the new style. Someday.
Closing this issue. Sorry again!