VC-LTL5 icon indicating copy to clipboard operation
VC-LTL5 copied to clipboard

Add .NET native AOT support

Open stevefan1999-personal opened this issue 2 years ago • 4 comments

Perhaps we can find a way to run ,NET but natively compiled down version. Because if Rust can be dealt with, why not .NET, or even Golang?

stevefan1999-personal avatar Jul 21 '22 16:07 stevefan1999-personal

After some research I think this is actually possible, take a look at this:

https://github.com/dotnet/runtime/blob/d3ab95d3be895a1950a46c559397780dbb3e9807/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets

Maybe we can just find a way to override the MSBuild property SdkNativeLibrary to inject VC-LTL based libraries in Microsoft.NETCore.Native.Windows.targets?

stevefan1999-personal avatar Jan 12 '24 18:01 stevefan1999-personal

image There it goes:

    <ItemGroup>
      <SdkNativeLibrary Include="advapi32.lib" />
      <SdkNativeLibrary Include="bcrypt.lib" />
      <SdkNativeLibrary Include="crypt32.lib" />
      <SdkNativeLibrary Include="iphlpapi.lib" />
      <SdkNativeLibrary Include="kernel32.lib" />
      <SdkNativeLibrary Include="mswsock.lib" />
      <SdkNativeLibrary Include="ncrypt.lib" />
      <SdkNativeLibrary Include="normaliz.lib" />
      <SdkNativeLibrary Include="ntdll.lib" />
      <SdkNativeLibrary Include="ole32.lib" />
      <SdkNativeLibrary Include="oleaut32.lib" />
      <SdkNativeLibrary Include="secur32.lib" />
      <SdkNativeLibrary Include="user32.lib" />
      <SdkNativeLibrary Include="version.lib" />
      <SdkNativeLibrary Include="ws2_32.lib" />
      <SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\6.2.9200.0\lib\x64\libucrt.lib" />
      <SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\6.2.9200.0\lib\x64\libvcruntime.lib" />
    </ItemGroup>
    <ItemGroup Condition="!Exists('$(IlcSdkPath)debugucrt.txt')">
      <!-- Force ucrt to be dynamically linked for release runtime -->
      <LinkerArg Include="/NODEFAULTLIB:ucrt.lib" />
      <LinkerArg Include="/NODEFAULTLIB:vcruntime.lib" />
      <LinkerArg Include="/DEFAULTLIB:libucrt.lib" />
      <LinkerArg Include="/DEFAULTLIB:libvcruntime.lib" />
    </ItemGroup>

stevefan1999-personal avatar Jan 12 '24 18:01 stevefan1999-personal

Yep, just adding these few <ItemGroup> to csproj, should work on any project:

	<ItemGroup>
		<SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\5.2.3790.0\lib\x64\libucrt.lib" />
		<SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\5.2.3790.0\lib\x64\libvcruntime.lib" />
		<LinkerArg Include="/DEFAULTLIB:libucrt.lib" />
		<LinkerArg Include="/DEFAULTLIB:libvcruntime.lib" />
		<LinkerArg Include="/NODEFAULTLIB:ucrt.lib" />
		<LinkerArg Include="/NODEFAULTLIB:vcruntime.lib" />
	</ItemGroup>

So what we need to figure out is how to add the MSBuild support and publish the right version on Nuget...

stevefan1999-personal avatar Jan 12 '24 19:01 stevefan1999-personal

Looks good.

Kenji Mouri

MouriNaruto avatar Jan 12 '24 23:01 MouriNaruto

新版本已经发布 https://github.com/Chuyu-Team/VC-LTL5/releases/tag/v5.0.10-Beta2

mingkuang-Chuyu avatar May 04 '24 16:05 mingkuang-Chuyu

新版本已经发布 https://github.com/Chuyu-Team/VC-LTL5/releases/tag/v5.0.10-Beta2

There could be a new README section about how it works, does it just work by installing the Nuget package?

stevefan1999-personal avatar May 06 '24 04:05 stevefan1999-personal

新版本已经发布 https://github.com/Chuyu-Team/VC-LTL5/releases/tag/v5.0.10-Beta2

There could be a new README section about how it works, does it just work by installing the Nuget package? README will update, thanks~

  1. Install YY-Thunks v5.0.10-Beta2 or leater
  2. modify the value of TargetFramework to net8.0-windows
  3. optional, if you need run on Windows XP, please modify the value of SupportedOSPlatformVersion to 5.1

mingkuang-Chuyu avatar May 06 '24 05:05 mingkuang-Chuyu

新版本已经发布 https://github.com/Chuyu-Team/VC-LTL5/releases/tag/v5.0.10-Beta2

There could be a new README section about how it works, does it just work by installing the Nuget package? README will update, thanks~

  1. Install YY-Thunks v5.0.10-Beta2 or leater
  2. modify the value of TargetFramework to net8.0-windows
  3. optional, if you need run on Windows XP, please modify the value of SupportedOSPlatformVersion to 5.1

Can confirm it worked like a charm:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <InvariantGlobalization>true</InvariantGlobalization>
	<TargetFramework>net8.0-windows</TargetFramework>
    <!--如果不支持XP这一行不需要添加SupportedOSPlatformVersion-->
    <SupportedOSPlatformVersion>5.1</SupportedOSPlatformVersion>
	<OptimizationPreference>Size</OptimizationPreference>
	<TrimMode>copyused</TrimMode>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="VC-LTL" Version="5.0.10-Beta2" />
    <PackageReference Include="YY-Thunks" Version="1.0.10-Beta3" />
  </ItemGroup>

</Project>

stevefan1999-personal avatar May 06 '24 07:05 stevefan1999-personal