dsplaisted / strongnamer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

<StrongNamerNetCoreAppVersion>$(BundledNETCoreAppTargetFrameworkVersion)</StrongNamerNetCoreAppVersion>
<StrongNamerNetCoreAppVersion Condition="'$(StrongNamerNetCoreAppVersion)' == ''">1.0</StrongNamerNetCoreAppVersion>

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:

<Error Condition="'$(MSBuildRuntimeType)' == 'Core' and '$(StrongNamerMinCoreVersionRequired)' > '$(StrongNamerNetCoreAppVersion)' "
Text="StrongNamer requires at least the .NET Core SDK v2.1 to run with 'dotnet build'"
ContinueOnError="false"
/>

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:

  1. The BundledNETCoreAppTargetFrameworkVersion tagets has no value. It has not been imported since the dotnet core sdk wasn't either. StrongNamerMinCoreVersionRequired is assigned the value 1.0.
  2. Since I'm using dotnet build instead of msbuild directly, MSBuildRuntimeType has the value Core.
  3. 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?

@onovotny I saw that this error condition was added in #41. Do you have any suggestion on how could it be changed to support .Net framework projects through 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!