Skip to content

Commit

Permalink
Add logic to gather respective WinMDs of dependent projection DLLs. (#…
Browse files Browse the repository at this point in the history
…855)

* Add logic to gather respective WinMDs of dependent projection DLLs.

* Fix check.
  • Loading branch information
manodasanW authored Jun 2, 2021
1 parent 806fe82 commit 3700e25
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
42 changes: 42 additions & 0 deletions nuget/Microsoft.Windows.CsWinRT.Authoring.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,49 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Generate a RuntimeConfig -->
<EnableDynamicLoading>true</EnableDynamicLoading>
<!-- Name the RuntimeConfig properly -->
<ProjectRuntimeConfigFileName>WinRT.Host.runtimeconfig.json</ProjectRuntimeConfigFileName>
<!-- Make sure WinRT.Runtime.dll and Microsoft.Windows.SDK.NET.dll get binplaced with authored component's dll -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<CsWinRTDetectDependentAuthoringWinMDs Condition="'$(CsWinRTDetectDependentAuthoringWinMDs)'==''">true</CsWinRTDetectDependentAuthoringWinMDs>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="AssemblyName" />
<CompilerVisibleProperty Include="AssemblyVersion" />
<CompilerVisibleProperty Include="CsWinRTComponent" />
<CompilerVisibleProperty Include="CsWinRTEnableLogging" />
<CompilerVisibleProperty Include="CsWinRTGeneratedFilesDir" />
<CompilerVisibleProperty Include="CsWinRTExe" />
<CompilerVisibleProperty Include="CsWinRTKeepGeneratedSources" />
<CompilerVisibleProperty Include="CsWinRTWindowsMetadata" />
<CompilerVisibleProperty Include="CsWinRTGenerateProjection" />
<CompilerVisibleProperty Include="CsWinRTAuthoringInputs" />
</ItemGroup>

<!-- Note this runs before the msbuild editor config file is generated because that is what is used to pass properties to the source generator. -->
<Target Name="CsWinRTSetAuthoringWinMDs" BeforeTargets="GenerateMSBuildEditorConfigFile;GenerateMSBuildEditorConfigFileCore" DependsOnTargets="CsWinRTRemoveWinMDReferences;GetAssemblyVersion;CsWinRTPrepareProjection" Condition="$(CsWinRTEnabled)">
<!-- Try to find WinMDs for respective projection DLLs by looking for WinMDs in the packages they come from. -->
<ItemGroup Condition="'$(CsWinRTDetectDependentAuthoringWinMDs)'=='true'">
<_CsWinRTRuntimeCopyLocalItemsFromNuGetPackage Include="@(RuntimeCopyLocalItems->HasMetadata('NuGetPackageVersion'))" />
<_CsWinRTDetectedPackages Include="%(_CsWinRTRuntimeCopyLocalItemsFromNuGetPackage.NuGetPackageId)\%(_CsWinRTRuntimeCopyLocalItemsFromNuGetPackage.NuGetPackageVersion)" Condition="@(_CsWinRTRuntimeCopyLocalItemsFromNuGetPackage->Count()) > 0" />
<_CsWinRTDetectedDistinctPackages Include="@(_CsWinRTDetectedPackages->Distinct())" />
<CsWinRTAuthoringDetectedWinMDs Include="$(NuGetPackageRoot)%(_CsWinRTDetectedDistinctPackages.Identity)\**\*.winmd" Condition="@(_CsWinRTDetectedDistinctPackages->Count()) > 0" />
</ItemGroup>

<ItemGroup>
<CsWinRTAuthoringWinMDs Include="@(CsWinRTAuthoringDetectedWinMDs)" />
<CsWinRTAuthoringWinMDs Include="@(CsWinRTInputs)" />
<CsWinRTAuthoringDistinctWinMDs Include="@(CsWinRTAuthoringWinMDs->Distinct())" />
</ItemGroup>
<PropertyGroup>
<CsWinRTAuthoringInputs>$(CsWinRTAuthoringInputs) @(CsWinRTAuthoringDistinctWinMDs->'"%(FullPath)"', ' ') </CsWinRTAuthoringInputs>
</PropertyGroup>
</Target>

<!-- For Project Reference consumers, copy the necessary WinRT DLLs to output directory -->
<ItemGroup>
<CsWinRTAuthoringDependencyDlls Condition="Exists('$(CsWinRTPath)lib\net5.0\WinRT.Host.Shim.dll')" Include="$(CsWinRTPath)lib\net5.0\WinRT.Host.Shim.dll" />
Expand Down Expand Up @@ -161,4 +198,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.
</ItemGroup>
</Target>

<!-- Copy Authored winmd to output folder -->
<Target Name="CsWinRTPlaceWinMDInOutputFolder" BeforeTargets="AfterBuild">
<Copy SourceFiles="$(CsWinRTGeneratedFilesDir)\$(AssemblyName).winmd" DestinationFolder="$(TargetDir)" UseHardlinksIfPossible="false" SkipUnchangedFiles="true" />
</Target>

</Project>
28 changes: 0 additions & 28 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<CsWinRTEnabled Condition="'$(CsWinRTEnabled)' != 'true'">false</CsWinRTEnabled>
<CsWinRTGenerateProjection Condition="!$(CsWinRTEnabled)">false</CsWinRTGenerateProjection>
<CsWinRTGenerateProjection Condition="'$(CsWinRTGenerateProjection)' == ''">true</CsWinRTGenerateProjection>
<AllowUnsafeBlocks Condition="'$(CsWinRTComponent)' == 'true'">true</AllowUnsafeBlocks>
<AllowUnsafeBlocks Condition="$(CsWinRTEnabled)">true</AllowUnsafeBlocks>
<CoreCompileDependsOn>CsWinRTIncludeProjection;CsWinRTRemoveWinMDReferences;$(CoreCompileDependsOn)</CoreCompileDependsOn>
<TrackFileAccess Condition="'$(CsWinRTComponent)' != 'true'">false</TrackFileAccess>
<!-- Make sure WinRT.Runtime.dll and Microsoft.Windows.SDK.NET.dll get binplaced with authored component's dll -->
<CopyLocalLockFileAssemblies Condition="'$(CsWinRTComponent)' == 'true'">true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<!-- Remove WinRT.Host.dll and WinRT.Host.Shim.dll references -->
Expand Down Expand Up @@ -122,31 +119,6 @@ $(CsWinRTFilters)
</ItemGroup>
</Target>

<ItemGroup Condition="'$(CsWinRTComponent)' == 'true'">
<CompilerVisibleProperty Include="AssemblyName" />
<CompilerVisibleProperty Include="AssemblyVersion" />
<CompilerVisibleProperty Include="CsWinRTComponent" />
<CompilerVisibleProperty Include="CsWinRTEnableLogging" />
<CompilerVisibleProperty Include="CsWinRTGeneratedFilesDir" />
<CompilerVisibleProperty Include="CsWinRTExe" />
<CompilerVisibleProperty Include="CsWinRTKeepGeneratedSources" />
<CompilerVisibleProperty Include="CsWinRTWindowsMetadata" />
<CompilerVisibleProperty Include="CsWinRTGenerateProjection" />
<CompilerVisibleProperty Include="CsWinRTAuthoringInputs" />
</ItemGroup>

<!-- Note this runs before the msbuild editor config file is generated because that is what is used to pass properties to the source generator. -->
<Target Name="CsWinRTSetAuthoringWinMDs" BeforeTargets="GenerateMSBuildEditorConfigFile;GenerateMSBuildEditorConfigFileCore" DependsOnTargets="CsWinRTRemoveWinMDReferences;GetAssemblyVersion;CsWinRTPrepareProjection" Condition="$(CsWinRTEnabled) And '$(CsWinRTComponent)' == 'true'">
<PropertyGroup>
<CsWinRTAuthoringInputs>$(CsWinRTAuthoringInputs) @(CsWinRTInputs->'"%(FullPath)"', ' ') @(CsWinRTAuthoringWinMDs->'"%(FullPath)"', ' ')</CsWinRTAuthoringInputs>
</PropertyGroup>
</Target>

<!-- Copy Authored winmd to output folder -->
<Target Name="CsWinRTPlaceWinMDInOutputFolder" Condition="'$(CsWinRTComponent)' == 'true'" BeforeTargets="AfterBuild">
<Copy SourceFiles="$(CsWinRTGeneratedFilesDir)\$(AssemblyName).winmd" DestinationFolder="$(TargetDir)" UseHardlinksIfPossible="false" SkipUnchangedFiles="true" />
</Target>

<Import Project="$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets" Condition="Exists('$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets')"/>
<Import Project="$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Authoring.targets" Condition="'$(CsWinRTComponent)' == 'true'"/>

Expand Down

0 comments on commit 3700e25

Please sign in to comment.