in src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs [393:448]
private void SetWinMDMetadata(IEnumerable<ITaskItem> runtimeWinMDs, ICollection<string> candidateImplementations)
{
foreach (var winMD in runtimeWinMDs.Where(w => _fileExists(w.ItemSpec)))
{
string imageRuntimeVersion = _tryGetRuntimeVersion(winMD.ItemSpec);
if (String.IsNullOrEmpty(imageRuntimeVersion))
continue;
// RAR sets ImageRuntime for everything but the only dependencies we're aware of are
// for WinMDs
winMD.SetMetadata(ReferenceImageRuntimeMetadata, imageRuntimeVersion);
bool isWinMD, isManaged;
TryParseRuntimeVersion(imageRuntimeVersion, out isWinMD, out isManaged);
if (isWinMD)
{
winMD.SetMetadata(ReferenceWinMDFileMetadata, "true");
if (isManaged)
{
winMD.SetMetadata(ReferenceWinMDFileTypeMetadata, WinMDFileTypeManaged);
}
else
{
winMD.SetMetadata(ReferenceWinMDFileTypeMetadata, WinMDFileTypeNative);
// Normally RAR will expect the native DLL to be next to the WinMD, but that doesn't
// work well for nuget packages since compile time assets cannot be architecture specific.
// We also explicitly set all compile time assets to not copy local so we need to
// make sure that this metadata is set on the runtime asset.
// Examine all runtime assets that are native winmds and add Implementation metadata
// We intentionally permit this to cross package boundaries to support cases where
// folks want to split their architecture specific implementations into runtime
// specific packages.
// Sample layout
// lib\netcore50\Contoso.Controls.winmd
// lib\netcore50\Contoso.Controls.xml
// runtimes\win10-arm\native\Contoso.Controls.dll
// runtimes\win10-x64\native\Contoso.Controls.dll
// runtimes\win10-x86\native\Contoso.Controls.dll
string fileName = Path.GetFileNameWithoutExtension(winMD.ItemSpec);
// determine if we have a Native WinMD that could be satisfied by this native dll.
if (candidateImplementations.Contains(fileName))
{
winMD.SetMetadata(ReferenceImplementationMetadata, fileName + ".dll");
}
}
}
}
}