Repository navigation
Support for dotnet publish - #4870
Conversation
| <PackageReference Include="System.CommandLine"> | ||
| <Version>0.1.0-e160909-1</Version> | ||
| </PackageReference> | ||
| <PackageReference Include="Microsoft.Build.Framework"> |
There was a problem hiding this comment.
We should not be adding dependency from the ILCompiler to MSBuild. The build task should be in its own assembly.
|
|
||
|
|
||
| var simdVectorLength = SimdVectorLength.Vector128Bit; | ||
| var targetDetails = new TargetDetails(TargetArchitecture.ARM64, TargetOS.Windows, TargetAbi.CoreRT, simdVectorLength); |
| </PackageReference> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\ILCompiler.TypeSystem\src\ILCompiler.TypeSystem.csproj" /> |
There was a problem hiding this comment.
Is this dependency really needed?
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Build.Framework"> | ||
| <Version>15.3.0-preview-000388-01</Version> |
There was a problem hiding this comment.
Can we depend on stable version of the packages?
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <RootNamespace>ILCompiler</RootNamespace> | ||
| <AssemblyName>ILCompiler.ManagedAssembliesBuildTask</AssemblyName> |
There was a problem hiding this comment.
I would give it a bit more generic name, e.g. ILCompiler.Build.Tasks. It is likely we will come up with more assorted build tasks to add to this assembly over time.
| </PackageReference> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ItemGroup> |
| <Version>15.3.409</Version> | ||
| </PackageReference> | ||
| <PackageReference Include="System.Reflection.Metadata"> | ||
| <Version>1.5.0</Version> |
There was a problem hiding this comment.
All our other projects use 1.4.2. Could you please use it here as well?
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "desktop", "desktop\desktop.csproj", "{CE9781B1-0028-4039-A48C-8193F0D28467}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.ManagedAssembliesBuildTask", "..\ILCompiler.ManagedAssembliesBuildTasks\src\ILCompiler.ManagedAssembliesBuildTask.csproj", "{DC752905-8E60-4514-8DD2-62ADE6DC18C9}" |
There was a problem hiding this comment.
Rename the directory to match the dll name
| List<ITaskItem> assembliesToSkipPublish = new List<ITaskItem>(); | ||
|
|
||
| ITaskItem[] assemblies = this.Assemblies; | ||
|
|
|
|
||
| public override bool Execute() | ||
| { | ||
| List<ITaskItem> list = new List<ITaskItem>(); |
There was a problem hiding this comment.
Nit: Can use var here since it is used a few lines later as well.
| } | ||
|
|
||
| // Skip the native apphost (whose name ends up colliding with the CoreRT output binary) and supporting assemblies | ||
| if (taskItem.ItemSpec.EndsWith("apphost.exe", StringComparison.OrdinalIgnoreCase) || taskItem.ItemSpec.Contains("hostfxr") || taskItem.ItemSpec.Contains("hostpolicy")) |
There was a problem hiding this comment.
Would these also be skipped in the foreach loop below? (Can we avoid hardcoding CoreCLR implementation details?)
| continue; | ||
| } | ||
|
|
||
| // Prototype aid - remove the native CoreCLR runtime pieces from the publish folder |
There was a problem hiding this comment.
Same question - would it be skipped more naturally in the foreach?
There was a problem hiding this comment.
Yes, however CoreCLR assembly modules don't seem to have metadata attached. Hopefully someone more knowledgeable will correct me here.
| using (var moduleStream = File.OpenRead(taskItem.ItemSpec)) | ||
| using (var module = new PEReader(moduleStream)) | ||
| { | ||
| var moduleMetadataReader = module.GetMetadataReader(); |
There was a problem hiding this comment.
Do we need to check module.HasMetadata first? (GetMetadataReader will throw if there's no metadata.)
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "desktop", "desktop\desktop.csproj", "{CE9781B1-0028-4039-A48C-8193F0D28467}" | ||
| EndProject | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ILCompiler.Build.Tasks", "..\ILCompiler.Build.Tasks\src\ILCompiler.Build.Tasks.csproj", "{44DE7F7B-AD73-40EA-87CC-554F2F57C38A}" |
There was a problem hiding this comment.
VS didn't generate an entry in the long GUID list below for this, or did you delete it?
There was a problem hiding this comment.
I did without considering it might be actual config info. Added back.
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <_NativeIntermediateAssembly Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename).exe')" /> |
There was a problem hiding this comment.
I think msbuild has a way to express the .exe that is hardcoded here. This won't work for #4718.
| } | ||
|
|
||
| // Prototype aid - remove the native CoreCLR runtime pieces from the publish folder | ||
| // TODO: Is this a correct approach? |
There was a problem hiding this comment.
@nattress Could I ask you to take a look at this?
There was a problem hiding this comment.
Does this get set for all native binaries? What happens if I want to deploy a native DLL with my CoreRT app and P/Invoke to it?
There was a problem hiding this comment.
After testing out a couple of scenarios - it breaks after publishing (native dlls are filtered out). That was exactly what I was looking for, thanks!
| ITaskItem taskItem = assemblies[i]; | ||
|
|
||
| // Skip crossgen images | ||
| if (taskItem.ItemSpec.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
It may be nice to cache itemSpec in a local. I will be a bit easier to read and a bit faster as well (each ItemSpec call is virtual interface call).
| coreRTFrameworkAssembliesToUse.Add(Path.GetFileName(x.ItemSpec)); | ||
| } | ||
|
|
||
| for (int i = 0; i < assemblies.Length; i++) |
There was a problem hiding this comment.
You can use foreach here as well.
|
|
||
| var coreRTFrameworkAssembliesToUse = new HashSet<string>(); | ||
|
|
||
| foreach (var x in SdkAssemblies) |
There was a problem hiding this comment.
We try to follow corefx coding conventions and only use var when the type is obvious from the right hand side (it is not obvious in this case).
| var list = new List<ITaskItem>(); | ||
| var assembliesToSkipPublish = new List<ITaskItem>(); | ||
|
|
||
| ITaskItem[] assemblies = this.Assemblies; |
There was a problem hiding this comment.
Nit: This local is not useful anymore. It is used in exactly one place in the foreach.
| // In the case of disk-based assemblies, this holds the file path | ||
| string itemSpec = taskItem.ItemSpec; | ||
|
|
||
| // Skip crossgen images |
There was a problem hiding this comment.
There should not be any *.ni.dll images anymore. Do you see any?
There was a problem hiding this comment.
There are none and none are being passed as inputs. Are we still supporting them?
There was a problem hiding this comment.
We are supporting them, but we are not using .ni.dll suffix for them.
Support for the dotnet publish command. Built on top of changes made by @nattress .
NuGet packages that target .NETCore specifically can be published safely, but most others targeting the .NETFramework cannot. Specifically anything to do with Reflection.Emit will fail at compile-time. Is this something we can/want to support?
As an aside, I'm certain there is a more elegant switch implementation than the one below.
cc @MichalStrehovsky @nattress