Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Support for dotnet publish - #4870

Merged
MichalStrehovsky merged 9 commits into
dotnet:masterfrom
A-And:publishSupport
Nov 8, 2017
Merged

MichalStrehovsky merged 9 commits into
dotnet:masterfrom
A-And:publishSupport

Conversation

@A-And

@A-And A-And commented Nov 3, 2017

Copy link
Copy Markdown
Contributor

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

Comment thread src/ILCompiler/src/ILCompiler.csproj Outdated
<PackageReference Include="System.CommandLine">
<Version>0.1.0-e160909-1</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build.Framework">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unused.

</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ILCompiler.TypeSystem\src\ILCompiler.TypeSystem.csproj" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this dependency really needed?

</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework">
<Version>15.3.0-preview-000388-01</Version>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>ILCompiler</RootNamespace>
<AssemblyName>ILCompiler.ManagedAssembliesBuildTask</AssemblyName>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/ILCompiler/src/ILCompiler.csproj Outdated
</PackageReference>
</ItemGroup>
<ItemGroup>
<ItemGroup>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unnecessary whitespace

<Version>15.3.409</Version>
</PackageReference>
<PackageReference Include="System.Reflection.Metadata">
<Version>1.5.0</Version>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All our other projects use 1.4.2. Could you please use it here as well?

Comment thread src/ILCompiler/ILCompiler.sln Outdated
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}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the directory to match the dll name

List<ITaskItem> assembliesToSkipPublish = new List<ITaskItem>();

ITaskItem[] assemblies = this.Assemblies;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extra line


public override bool Execute()
{
List<ITaskItem> list = new List<ITaskItem>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question - would it be skipped more naturally in the foreach?

@A-And A-And Nov 6, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS didn't generate an entry in the long GUID list below for this, or did you delete it?

@A-And A-And Nov 6, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did without considering it might be actual config info. Added back.

</ItemGroup>

<ItemGroup>
<_NativeIntermediateAssembly Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename).exe')" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think msbuild has a way to express the .exe that is hardcoded here. This won't work for #4718.

@A-And A-And changed the title Support for dotnet publish [WIP] Support for dotnet publish Nov 6, 2017
}

// Prototype aid - remove the native CoreCLR runtime pieces from the publish folder
// TODO: Is this a correct approach?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nattress Could I ask you to take a look at this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@A-And A-And Nov 7, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@A-And A-And changed the title [WIP] Support for dotnet publish Support for dotnet publish Nov 7, 2017
ITaskItem taskItem = assemblies[i];

// Skip crossgen images
if (taskItem.ItemSpec.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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++)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use foreach here as well.


var coreRTFrameworkAssembliesToUse = new HashSet<string>();

foreach (var x in SdkAssemblies)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md

var list = new List<ITaskItem>();
var assembliesToSkipPublish = new List<ITaskItem>();

ITaskItem[] assemblies = this.Assemblies;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should not be any *.ni.dll images anymore. Do you see any?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are none and none are being passed as inputs. Are we still supporting them?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are supporting them, but we are not using .ni.dll suffix for them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants