@@ -26,7 +26,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
2626
2727 <!-- For CX projects, CppWinRT will never output a winmd-->
2828 <!-- NOTE: We don't set a default here as the default requires evaluation of project references
29- and this is done by the ComputeCppWinRTResolvedWinMD target. -->
29+ and this is done by the CppWinRTComputeGenerateWindowsMetadata target. -->
3030 <CppWinRTGenerateWindowsMetadata Condition =" '$(CppWinRTGenerateWindowsMetadata)' == '' AND '$(XamlLanguage)' == 'C++' " >false</CppWinRTGenerateWindowsMetadata >
3131 <!-- For CX projects, turn off the component projection generation-->
3232 <CppWinRTEnableComponentProjection Condition =" '$(CppWinRTEnableComponentProjection)' == '' AND '$(XamlLanguage)' == 'C++' " >false</CppWinRTEnableComponentProjection >
@@ -40,11 +40,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.
4040 <!-- TEMP: Override NuGet SDK's erroneous setting in uap.props -->
4141 <WindowsSDK_MetadataFoundationPath Condition =" ('$(WindowsSDK_MetadataFoundationPath)'!='') And !Exists($(WindowsSDK_MetadataFoundationPath))" >$(WindowsSDK_MetadataPathVersioned)</WindowsSDK_MetadataFoundationPath >
4242
43- <GetTargetPathDependsOn >
44- $(GetTargetPathDependsOn);ComputeCppWinRTResolvedWinMD;CppWinRTResolvedWinMD;
45- </GetTargetPathDependsOn >
4643 <PrepareForBuildDependsOn >
47- $(PrepareForBuildDependsOn);CppWinRTVerifyKitVersion;
44+ $(PrepareForBuildDependsOn);
45+ CppWinRTVerifyKitVersion;
4846 </PrepareForBuildDependsOn >
4947 <!-- Note: Before* targets run before Compute* targets. -->
5048 <BeforeMidlCompileTargets >
@@ -57,9 +55,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
5755 $(AfterMidlTargets);
5856 GetCppWinRTMdMergeInputs;
5957 CppWinRTMergeProjectWinMDInputs;
60- ComputeCppWinRTResolvedWinMD;
61- CppWinRTResolvedWinMD;
62- CppWinRTResolvedWinMDToOutputDirectory;
58+ GetResolvedWinMD;
59+ CppWinRTCopyWinMDToOutputDirectory;
6360 </AfterMidlTargets >
6461 <ResolveAssemblyReferencesDependsOn >
6562 $(ResolveAssemblyReferencesDependsOn);GetCppWinRTProjectWinMDReferences;CppWinRTRemoveStaticLibraries;
@@ -122,21 +119,66 @@ Copyright (C) Microsoft Corporation. All rights reserved.
122119 </Target >
123120
124121 <!-- Target used only to evaluate CppWinRTGenerateWindowsMetadata if it doesn't already have a value -->
125- <Target Name =" ComputeCppWinRTResolvedWinMD "
126- Condition = " '$(CppWinRTGenerateWindowsMetadata)' == '' "
127- DependsOnTargets = " GetCppWinRTMdMergeInputs " >
122+ <Target Name =" CppWinRTComputeGenerateWindowsMetadata "
123+ DependsOnTargets = " CppWinRTComputeXamlGeneratedMidlInputs;GetCppWinRTProjectWinMDReferences;$(CppWinRTComputeGenerateWindowsMetadataDependsOn) " >
124+
128125 <PropertyGroup >
129- <CppWinRTGenerateWindowsMetadata Condition =" '@(CppWinRTMdMergeInputs)'!= ''" >true</CppWinRTGenerateWindowsMetadata >
130- <CppWinRTGenerateWindowsMetadata Condition =" '@(CppWinRTMdMergeInputs)'== ''" >false</CppWinRTGenerateWindowsMetadata >
126+ <!-- For static libraries, only idl causes a winmd to be generated.
127+ For exe/dll, static libraries that produce a WinMD will be merged,
128+ so they also cause a WinMD to be generated-->
129+ <CppWinRTGenerateWindowsMetadata Condition =" '$(ConfigurationType)' != 'StaticLibrary' AND '@(CppWinRTStaticProjectWinMDReferences)@(Midl)'!= ''" >true</CppWinRTGenerateWindowsMetadata >
130+ <CppWinRTGenerateWindowsMetadata Condition =" '$(ConfigurationType)' == 'StaticLibrary' AND '@(Midl)'!= ''" >true</CppWinRTGenerateWindowsMetadata >
131+
132+ <!-- At this point we checked all cases where we do generate a WinMD.
133+ The remaining option is no WinMD. -->
134+ <CppWinRTGenerateWindowsMetadata Condition =" '$(CppWinRTGenerateWindowsMetadata)'== ''" >false</CppWinRTGenerateWindowsMetadata >
131135 </PropertyGroup >
136+
132137 </Target >
133138
134- <Target Name =" CppWinRTResolvedWinMD"
135- Condition =" '$(CppWinRTGenerateWindowsMetadata)' == 'true'"
139+ <Target Name =" ComputeGetResolvedWinMD"
140+ Condition =" '$(CppWinRTGenerateWindowsMetadata)' == ''" >
141+ <!-- If CppWinRTGenerateWindowsMetadata is not defined, compute it.-->
142+ <!-- We use Calltarget, so we don't run anything including DependsOnTargets
143+ targets if $(CppWinRTGenerateWindowsMetadata) already has a value.-->
144+ <CallTarget Targets =" CppWinRTComputeGenerateWindowsMetadata" />
145+ </Target >
146+
147+ <!-- This target overrides the GetResolvedWinMD target used to resolve the WinMD for native projects
148+ so it is aware of the C++/WinRT generated WinMD.
149+ Since not every project that consumes C++/WinRT uses it to generate a WinMD,
150+ we need to keep the CX logic as well. -->
151+ <Target Name =" GetResolvedWinMD"
152+ DependsOnTargets =" ComputeGetResolvedWinMD"
136153 Returns =" @(WinMDFullPath)" >
154+
155+ <!-- Copied from the CX GetResolvedWinMD target in Microsoft.CppBuild.targets -->
137156 <ItemGroup >
138- <WinMDFullPath Remove =" @(WinMDFullPath)" />
139- <WinMDFullPath Include =" $(CppWinRTProjectWinMD)" >
157+ <!-- To evaluate the GenerateWindowsMetadata value we need @(Link) to contains at least one element-->
158+ <Link Include =" tmp" Condition =" '@(Link)'==''" >
159+ <DeleteSoon >true</DeleteSoon >
160+ </Link >
161+
162+ <!-- Condition is modified to only do this if CppWinRTGenerateWindowsMetadata is not true. -->
163+ <WinMDFullPath Condition =" '%(Link.GenerateWindowsMetadata)' == 'true' AND '$(CppWinRTGenerateWindowsMetadata)' != 'true'"
164+ Include =" @(Link->Metadata('WindowsMetadataFile')->FullPath()->Distinct()->ClearMetadata())" >
165+ <TargetPath >$([System.IO.Path]::GetFileName('%(Link.WindowsMetadataFile)'))</TargetPath >
166+ <Primary >true</Primary >
167+ </WinMDFullPath >
168+
169+ <WinMDFullPath >
170+ <Implementation >$(WinMDImplementationPath)$(TargetName)$(TargetExt)</Implementation >
171+ <FileType >winmd</FileType >
172+ <WinMDFile >true</WinMDFile >
173+ <ProjectType >$(ConfigurationType)</ProjectType >
174+ </WinMDFullPath >
175+
176+ <Link Remove =" @(Link)" Condition =" '%(Link.DeleteSoon)' == 'true'" />
177+ </ItemGroup >
178+
179+ <!-- Add C++/WinRT primary WinMD to the WinMDFullPath if CppWinRTGenerateWindowsMetadata is true -->
180+ <ItemGroup >
181+ <WinMDFullPath Include =" $(CppWinRTProjectWinMD)" Condition =" '$(CppWinRTGenerateWindowsMetadata)' == 'true'" >
140182 <TargetPath >$([System.IO.Path]::GetFileName('$(CppWinRTProjectWinMD)'))</TargetPath >
141183 <Primary >true</Primary >
142184 <Implementation Condition =" '$(TargetExt)' == '.dll'" >$(WinMDImplementationPath)$(RootNamespace)$(TargetExt)</Implementation >
@@ -146,7 +188,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
146188 <ProjectType >$(ConfigurationType)</ProjectType >
147189 </WinMDFullPath >
148190 </ItemGroup >
149- <Message Text =" CppWinRTResolvedWinMD: @(WinMDFullPath->'%(FullPath)')" Importance =" $(CppWinRTVerbosity)" />
191+
192+ <Message Text =" GetResolvedWinMD: @(WinMDFullPath->'%(FullPath)')" Importance =" $(CppWinRTVerbosity)" />
150193 </Target >
151194
152195 <!-- Static library reference files are merged into the project that
@@ -425,9 +468,9 @@ $(XamlMetaDataProviderPch)
425468
426469 <!-- Only copy winmd to output folder if CppWinRTGenerateWindowsMetadata is true -->
427470 <!-- Note that Condition is evaluated before DependsOnTargets are run -->
428- <Target Name =" CppWinRTResolvedWinMDToOutputDirectory "
471+ <Target Name =" CppWinRTCopyWinMDToOutputDirectory "
429472 Condition =" '$(CppWinRTGenerateWindowsMetadata)' == 'true'"
430- DependsOnTargets =" CppWinRTMergeProjectWinMDInputs;$(CppWinRTResolvedWinMDToOutputDirectoryDependsOn )"
473+ DependsOnTargets =" CppWinRTMergeProjectWinMDInputs;$(CppWinRTCopyWinMDToOutputDirectoryDependsOn )"
431474 Inputs =" @(_MdMergedOutput)"
432475 Outputs =" $(CppWinRTProjectWinMD)" >
433476 <Copy UseHardlinksIfPossible =" $(CppWinRTUseHardlinksIfPossible)"
0 commit comments