MichalStrehovsky / zerosharp

Demo of the potential of C# for systems programming with the .NET native ahead-of-time compilation technology.
2.02k stars 105 forks source link

Cannot find ILC #22

Open matty-hall opened 3 years ago

matty-hall commented 3 years ago

Thank you so much for this! So, I've followed the instructions and building isn't working (I'm trying efi-no-runtime). A few notes:

  1. The readme says that VS2019 is required, but the project doesn't build at all in 2019 (stating that the 6.0 SDK isn't supported). So, I installed the 2022 preview.

  2. A build in VS2022 works and successfully generates a binary. However, a dumpbin on the binary shows the subsystem as Windows CUI, so the extra "stuff" (i.e. in the CSPROJ) doesn't appear to be hooked up.

  3. Invoking "dotnet publish -r windows-x64 -c Release" also does not working, yielding: C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error NETSDK1083: The specified RuntimeIdentifier 'windows-x64' is not recognized. [C:\Users\m\Downloads\zerosharp-master\zerosharp-master\efi-no-runtime\efinoruntime.csproj]

  4. The readme also claims that build.cmd is redundant w/ the CSPROJ file, but the file names are totally different (i.e. build.cmd refers to 'zerosharp' while the output name in the CSPROJ is 'efinoruntime')

  5. ILC isn't in the nuget package. Mine was cached at C:\Users[username].nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-alpha.1.21504.4\ but the tools directory (nor any directory in there) has an ILC.exe that the build.cmd is looking for.

Given that I can successfully compile the code to a managed binary, I'm perfectly fine using a batch file rather than the CSPROJ file to link to native, so I think the issue really is finding where ILC.exe is located? Help is greatly appreciated!

MichalStrehovsky commented 3 years ago
  1. It should work with VS2019, but VS2019 has a checkbox in the settings that you need to check to enable preview SDKs.
  2. I only really tried it with dotnet from the command line. The VS requirement is because it needs link.exe and the Windows SDK and VS conveniently installs those.
  3. The RID is win-x64, not windows-x64. My bad. Fixed the docs.
  4. Yeah, I didn't bother aligning the names.
  5. ilc.exe is in the runtime.win-x64.microsoft.dotnet.ilcompiler package, not in microsoft.dotnet.ilcompiler package.
matty-hall commented 3 years ago

Thank you so much! I was able to get VS2019 working for a managed build (which works). The setting you're referencing is under Tools | Options | Environment | Preview Features | Use Previews of the .NET SDK.

After getting that working, I now magically have "runtime.win-x64.microsoft.dotnet.ilcompiler" in my .nuget folder, which wasn't the case after building in VS2022 Preview (I only had microsoft.dotnet.ilcompiler). I think that gives me everything I need to just hook things up from the command line.

For the sake of reference, dotnet publish still fails even after using "win-x64" rather than "windows-x64" with the following. This doesn't matter to me since I really just needed ilc.exe, but I wanted to add this for anyone else who runs into it:

Running 'dotnet publish -r win-x64 -c Release' still fails with the following:

Microsoft (R) Build Engine version 17.0.0-preview-21460-01+8f208e609 for .NET Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore... efinoruntime.csproj : error NU1102: Unable to find package Microsoft.NETCore.App.Runtime.win-x64 with version (= 6.0.0-rc.1.21451.13) efinoruntime.csproj : error NU1102: - Found 11 version(s) in dotnet-experimental [ Nearest version: 6.0.0-s390x.1.20553.1 ] efinoruntime.csproj : error NU1101: Unable to find package Microsoft.WindowsDesktop.App.Runtime.win-x64. No packages exist with this id in source(s): dotnet-experimental efinoruntime.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.App.Runtime.win-x64. No packages exist with this id in source(s): dotnet-experimental Failed to restore efinoruntime.csproj (in 931 ms).

Thank you so much for the help and for all of this work - really appreciate it!

MichalStrehovsky commented 3 years ago

efinoruntime.csproj : error NU1101: Unable to find package Microsoft.WindowsDesktop.App.Runtime.win-x64. No packages exist with this id in source(s): dotnet-experimental

Maybe try deleting the <clear /> line from NuGet.config to allow restoring from NuGet.org.

But if you're comfortable doing this with the batch scripts, it's better that way.