ILSupport: Can't build template project
Steps to reproduce:
- Create C# Class Library (.NET Standard) with IL Support
- Run
dotnet buildagainst it
This presents the following error
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 23.11 ms for C:\Users\p-kel\source\repos\IL Experiments\IL Experiments\IL Experiments.csproj.
C:\Users\p-kel\source\repos\IL Experiments\IL Experiments\IL Experiments.csproj(21,5): error MSB4062: The "Microsoft.Build.Tasks.GetFrameworkSdkPath" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Build FAILED.
C:\Users\p-kel\source\repos\IL Experiments\IL Experiments\IL Experiments.csproj(21,5): error MSB4062: The "Microsoft.Build.Tasks.GetFrameworkSdkPath" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.61
And the output of dotnet --info:
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\
Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33
.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Considering this is a .NET Standard project I would think this should build regardless, since a non IL Support project would just fine.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 20 (20 by maintainers)
Frankly, all of this is getting hackish, and for the new .NET projects, it should probably be published as a project SDK, so the usage would simply be to change the SDK from:
<Project Sdk="Microsoft.NET.Sdk">to<Project Sdk="ILSupport.NET.Sdk">and targets would be automatically imported. And by the time I get to do this, maybe Microsoft will have added a better way to call ildasm.And all this aside, a better way to use custom IL is probably to move all the IL code to an .ilproj with the Microsoft.NET.Sdk.IL project SDK as in the System.Runtime.CompilerServices.Unsafe project: https://github.com/dotnet/corefx/blob/master/src/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.ilproj
It’s not published to NuGet yet, but it seems people are able to use it: https://github.com/dotnet/coreclr/issues/20816
I looked around a bit for a solution, and it appears it might be a bit more complicated than expected.
To have access to ILDasm with .NET Core, and to make it work cross-platform, it seems I’ll have to make new .NET Core / Standard project templates that use the Microsoft.NETCore.ILDAsm NuGet package, and then somehow figure out where the binary gets installed.
On macOS, it seems to be ~/.nuget/packages/runtime.osx-x64.microsoft.netcore.ildasm/2.0.8/runtimes/osx-x64/native/ildasm. I expect it to be %UserProfile%\.nuget\packages\runtime.win-x64.microsoft.netcore.ildasm\2.0.8\runtimes\win-x64\native\ildasm.exe or something similar.
The package reference looks like this:
<PackageReference Include="Microsoft.NETCore.ILDAsm" Version="2.0.8" />You could try adding this package to your project, and then a fallback for: %UserProfile%\.nuget\packages\runtime.win-x64.microsoft.netcore.ildasm\2.0.8\runtimes\win-x64\native\ildasm.exe or whatever is the correct path to ILDasm is.
It might be necessary to instead reference the “runtime.win-x64.Microsoft.NETCore.ILDAsm” package to have the binary installed.
This issue on the dotnet repository is tracking the problem: https://github.com/dotnet/cli/issues/6223
From this error, it seems $(FrameworkSdkPath) is empty under .NET Core 3.0.
The location fallbacks for ILDasm are those lines in your csproj: https://github.com/ins0mniaque/ILSupport/blob/7e440fbf71930a12449560d6fcaca0e9c13ba6bb/IL Support.ProjectTemplates/IL Support.targets#L26-L43
Meanwhile, you can add another fallback pointing directly to ILDasm. The correct fix would be to find the variable that gives the correct $(FrameworkSdkPath) under .NET Core 3.0.
I’ll investigate as soon as possible.