[mono] Add MonoAOTCompiler MSBuild Task to produce NuPkg (#46537)
authorMitchell Hwang <mitchhwang1418@gmail.com>
Wed, 6 Jan 2021 20:43:12 +0000 (15:43 -0500)
committerGitHub <noreply@github.com>
Wed, 6 Jan 2021 20:43:12 +0000 (15:43 -0500)
* Test workload

* Remove hardcoded path to MonoAOTCompiler

Remove changes related to testing the MonoAOTCompiler NuPkg

Remove changes to deprecated files that led to file additions

* Inline pkg descriptions for MonoAOTCompiler Task and workload packs

* Remove Workload AOT additions

* Replace _ILLinkTasksDirectoryRoot with _AOTTasksDirectoryRoot

* Add TargetsMobile condition

* Remove temporary variables

* Reword MonoAOTCompiler NuPkg description

* Remove NuPkg import of MonoAOTCompiler UsingTask

* Add MonoAOTCompilerTaskAssemblyPath property

* Cleanup Microsoft.NET.Runtime.MonoAOTCompiler.Tasks.props

* Add README.md with example of using the NuPkg

* Specify the package files for the aot task, in the project itself

* Add comment for GetFilesToPackage target

* Update README.md

Co-authored-by: Ankit Jain <radical@gmail.com>
Co-authored-by: Steve Pfister <steve.pfister@microsoft.com>
Co-authored-by: Mitchell Hwang <mitchell.hwang@microsoft.com>
Co-authored-by: Ankit Jain <radical@gmail.com>
src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj [new file with mode: 0644]
src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/README.md [new file with mode: 0644]
src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/build/Microsoft.NET.Runtime.MonoAOTCompiler.Task.props [new file with mode: 0644]
src/mono/netcore/nuget/mono-packages.proj
src/tasks/AotCompilerTask/MonoAOTCompiler.csproj

diff --git a/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj b/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj
new file mode 100644 (file)
index 0000000..b60e455
--- /dev/null
@@ -0,0 +1,15 @@
+<Project DefaultTargets="Build">
+  <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props))" />
+
+  <PropertyGroup>
+    <PackageDescription>Provides the MonoAOTCompiler task</PackageDescription>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="$(RepoTasksDir)AotCompilerTask\MonoAOTCompiler.csproj" />
+
+    <PackageFile Include="build\$(MSBuildProjectName).props" TargetPath="build" />
+  </ItemGroup>
+
+  <Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
+</Project>
diff --git a/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/README.md b/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/README.md
new file mode 100644 (file)
index 0000000..63c8bf4
--- /dev/null
@@ -0,0 +1,35 @@
+# MonoAOTCompiler MSBuild Task NuPkg
+The `MonoAOTCompiler` MSBuild task is also useful outside the context of `dotnet/runtime`. The task is made available through a NuGet Package containing the `MonoAOTCompiler.dll` assembly produced from building `MonoAOTCompiler.csproj`. To use the task in a project, reference the NuGet package, with the appropriate nuget source.
+
+## NuGet.config
+```
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <packageSources>
+    <add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
+  </packageSources>
+</configuration>
+```
+
+## In the project file
+```
+<!-- Import the NuGet package into the project -->
+<ItemGroup>
+    <PackageReference Include="Microsoft.NET.Runtime.MonoAOTCompiler.Task" Version="<desired-dotnet-6-sdk-version>" />
+</ItemGroup>
+
+<!-- Set up the MSBuild task using the assembly path provided by the NuGet package -->
+<UsingTask TaskName="MonoAOTCompiler"
+           AssemblyFile="$(MonoAOTCompilerTaskAssemblyPath)"/>
+
+<!-- Use the MonoAOTCompiler task in a target -->
+<Target>
+    <MonoAOTCompiler 
+        CompilerBinaryPath="$(CompilerBinaryPath)"
+        Assemblies="@(Assemblies)"
+        <!-- Other parameters -->
+        >
+        <Output TaskParameter="CompiledAssemblies" ItemName="CompiledAssemblies" />
+    </MonoAOTCompiler>
+</Target>
+```
diff --git a/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/build/Microsoft.NET.Runtime.MonoAOTCompiler.Task.props b/src/mono/netcore/nuget/Microsoft.NET.Runtime.MonoAOTCompiler.Task/build/Microsoft.NET.Runtime.MonoAOTCompiler.Task.props
new file mode 100644 (file)
index 0000000..2732cb7
--- /dev/null
@@ -0,0 +1,5 @@
+<Project>
+  <PropertyGroup>
+    <MonoAOTCompilerTaskAssemblyPath>$(MSBuildThisFileDirectory)..\tools\net5.0\MonoAOTCompiler.dll</MonoAOTCompilerTaskAssemblyPath>
+  </PropertyGroup>
+</Project>
index 0bea763..9359f34 100644 (file)
@@ -15,4 +15,8 @@
   <ItemGroup Condition="'$(TargetOS)' == 'iOS'">
     <ProjectReference Include="Microsoft.NET.Runtime.iOS.Sample.Mono\Microsoft.NET.Runtime.iOS.Sample.Mono.pkgproj" />
   </ItemGroup>
+
+  <ItemGroup Condition="'$(TargetsMobile)' == 'true'">
+    <ProjectReference Include="Microsoft.NET.Runtime.MonoAOTCompiler.Task\Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj" />
+  </ItemGroup>
 </Project>
index 66d2cfb..82f2908 100644 (file)
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
   </ItemGroup>
+
+  <!-- GetFilesToPackage assists to place `MonoAOTCompiler.dll` in a NuGet package in Microsoft.NET.Runtime.MonoAOTCompiler.Task.pkgproj for external use -->
+  <Target Name="GetFilesToPackage" Returns="@(FilesToPackage)">
+    <ItemGroup>
+      <FilesToPackage Include="$(OutputPath)$(NetCoreAppToolCurrent)\$(AssemblyName).dll" TargetPath="tools\$(NetCoreAppToolCurrent)" />
+    </ItemGroup>
+  </Target>
 </Project>