Skip to content

Commit fcdbc24

Browse files
authored
Fix bug where CppWinRT would drop static library references and add a test for the scenario. (#506)
1 parent c632231 commit fcdbc24

18 files changed

+675
-8
lines changed

nuget/Microsoft.Windows.CppWinRT.targets

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
6767
CppWinRTCopyWinMDToOutputDirectory;
6868
</AfterMidlTargets>
6969
<ResolveAssemblyReferencesDependsOn>
70-
$(ResolveAssemblyReferencesDependsOn);GetCppWinRTProjectWinMDReferences;CppWinRTRemoveStaticLibraries;
70+
$(ResolveAssemblyReferencesDependsOn);GetCppWinRTProjectWinMDReferences;CppWinRTMarkStaticLibrariesPrivate;
7171
</ResolveAssemblyReferencesDependsOn>
7272
<!-- Note: Before* targets run before Compute* targets. -->
7373
<BeforeClCompileTargets>
@@ -204,15 +204,18 @@ Copyright (C) Microsoft Corporation. All rights reserved.
204204
<Message Text="GetResolvedWinMD: @(WinMDFullPath->'%(FullPath)')" Importance="$(CppWinRTVerbosity)"/>
205205
</Target>
206206

207-
<!-- Static library reference files are merged into the project that
208-
references it. They shouldn't be included as actual project references.
209-
Make sure that we've ran the GetCppWinRTProjectWinMDReferences target
210-
and then remove them. -->
211-
<Target Name="CppWinRTRemoveStaticLibraries"
212-
DependsOnTargets="GetCppWinRTProjectWinMDReferences"
207+
<!-- Static library reference WinMDs are merged into the project WinMD that
208+
references it and might have the same name because they often share namespace.
209+
Therefore they shouldn't be copied to the output folder
210+
because they might override files in the output folder with the
211+
same name, causing missing types. -->
212+
<Target Name="CppWinRTMarkStaticLibrariesPrivate"
213+
DependsOnTargets="ResolveProjectReferences"
213214
Returns="@(_ResolvedProjectReferencePaths)">
214215
<ItemGroup>
215-
<_ResolvedProjectReferencePaths Remove="@(_ResolvedProjectReferencePaths)" Condition="'%(_ResolvedProjectReferencePaths.ProjectType)' == 'StaticLibrary'" />
216+
<_ResolvedProjectReferencePaths Condition="'%(_ResolvedProjectReferencePaths.ProjectType)' == 'StaticLibrary'">
217+
<Private>false</Private>
218+
</_ResolvedProjectReferencePaths>
216219
</ItemGroup>
217220
</Target>
218221

test/nuget/NuGetTest.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestRuntimeComponentCSharp"
3939
EndProject
4040
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestRuntimeComponentNamespaceUnderscore", "TestRuntimeComponentNamespaceUnderscore\TestRuntimeComponentNamespaceUnderscore.vcxproj", "{8717FA32-34A8-457D-B77B-AE005703EB55}"
4141
EndProject
42+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestRuntimeComponentCXReferencingWinRTStaticLibrary", "TestRuntimeComponentCXReferencingWinRTStaticLibrary\TestRuntimeComponentCXReferencingWinRTStaticLibrary.vcxproj", "{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}"
43+
EndProject
44+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestStaticLibrary7", "TestStaticLibrary7\TestStaticLibrary7.vcxproj", "{F89C2185-7834-443D-A449-53BD52FFEA3B}"
45+
EndProject
4246
Global
4347
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4448
Debug|ARM = Debug|ARM
@@ -253,6 +257,36 @@ Global
253257
{8717FA32-34A8-457D-B77B-AE005703EB55}.Release|x64.Build.0 = Release|x64
254258
{8717FA32-34A8-457D-B77B-AE005703EB55}.Release|x86.ActiveCfg = Release|Win32
255259
{8717FA32-34A8-457D-B77B-AE005703EB55}.Release|x86.Build.0 = Release|Win32
260+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|ARM.ActiveCfg = Debug|ARM
261+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|ARM.Build.0 = Debug|ARM
262+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|ARM64.ActiveCfg = Debug|ARM64
263+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|ARM64.Build.0 = Debug|ARM64
264+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|x64.ActiveCfg = Debug|x64
265+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|x64.Build.0 = Debug|x64
266+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|x86.ActiveCfg = Debug|Win32
267+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Debug|x86.Build.0 = Debug|Win32
268+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|ARM.ActiveCfg = Release|ARM
269+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|ARM.Build.0 = Release|ARM
270+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|ARM64.ActiveCfg = Release|ARM64
271+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|ARM64.Build.0 = Release|ARM64
272+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|x64.ActiveCfg = Release|x64
273+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|x64.Build.0 = Release|x64
274+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|x86.ActiveCfg = Release|Win32
275+
{FF846D79-F4B8-495A-9FB4-79BAAEB98E4F}.Release|x86.Build.0 = Release|Win32
276+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Debug|ARM.ActiveCfg = Debug|ARM
277+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Debug|ARM.Build.0 = Debug|ARM
278+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Debug|ARM64.ActiveCfg = Debug|Win32
279+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Debug|x64.ActiveCfg = Debug|x64
280+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Debug|x64.Build.0 = Debug|x64
281+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Debug|x86.ActiveCfg = Debug|Win32
282+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Debug|x86.Build.0 = Debug|Win32
283+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Release|ARM.ActiveCfg = Release|ARM
284+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Release|ARM.Build.0 = Release|ARM
285+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Release|ARM64.ActiveCfg = Release|Win32
286+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Release|x64.ActiveCfg = Release|x64
287+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Release|x64.Build.0 = Release|x64
288+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Release|x86.ActiveCfg = Release|Win32
289+
{F89C2185-7834-443D-A449-53BD52FFEA3B}.Release|x86.Build.0 = Release|Win32
256290
EndGlobalSection
257291
GlobalSection(SolutionProperties) = preSolution
258292
HideSolutionNode = FALSE
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "pch.h"
2+
#include "CxClass.h"
3+
4+
using namespace TestRuntimeComponentCXLibrary;
5+
using namespace Platform;
6+
7+
CxClass::CxClass(TestStaticLibrary7Class^ c)
8+
{
9+
c->Test();
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
namespace TestRuntimeComponentCXLibrary
4+
{
5+
public ref class CxClass sealed
6+
{
7+
public:
8+
CxClass(TestStaticLibrary7Class^ c);
9+
};
10+
}

0 commit comments

Comments
 (0)