Skip to content

Commit 7c0c940

Browse files
Make sure the AutoImports.props is only included once per .NET version (#8204)
Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
1 parent 667545f commit 7c0c940

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/Workload/Microsoft.Maui.Sdk/Microsoft.Maui.Sdk.csproj

+24
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,28 @@
9393
</ItemGroup>
9494
</Target>
9595

96+
<Target Name="_GenerateAutoImport"
97+
BeforeTargets="Build;AssignTargetPaths"
98+
DependsOnTargets="SetVersions"
99+
Inputs="$(MSBuildProjectFile);$(MauiRootDirectory)eng/Versions.props;Sdk/AutoImport.in.props"
100+
Outputs="$(IntermediateOutputPath)AutoImport.props">
101+
<ReplaceText
102+
Input="Sdk/AutoImport.in.props"
103+
Output="$(IntermediateOutputPath)AutoImport.props"
104+
OldValue="@MAUI_DOTNET_VERSION@"
105+
NewValue="$(_MauiDotNetVersion)"
106+
/>
107+
<ItemGroup>
108+
<None
109+
Include="$(IntermediateOutputPath)AutoImport.props"
110+
Link="Sdk/AutoImport.props"
111+
CopyToOutputDirectory="PreserveNewest"
112+
Pack="true"
113+
PackagePath="Sdk"
114+
Visible="false"
115+
/>
116+
<FileWrites Include="$(IntermediateOutputPath)AutoImport.props" />
117+
</ItemGroup>
118+
</Target>
119+
96120
</Project>

src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.props src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.in.props

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!-- all <ItemGroup/>'s must check if $(EnableDefaultMauiItems) is true -->
2+
<!-- all <ItemGroup/>'s must include $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '@MAUI_DOTNET_VERSION@')) -->
23
<Project>
34

45
<ItemDefinitionGroup>
@@ -7,7 +8,7 @@
78
</MauiXaml>
89
</ItemDefinitionGroup>
910

10-
<ItemGroup Condition=" '$(UseMaui)' == 'true' and ('$(ImplicitUsings)' == 'true' or '$(ImplicitUsings)' == 'enable') ">
11+
<ItemGroup Condition=" '$(UseMaui)' == 'true' and ('$(ImplicitUsings)' == 'true' or '$(ImplicitUsings)' == 'enable') and '$(TargetFrameworkVersion)' != '' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '@MAUI_DOTNET_VERSION@')) ">
1112
<!-- %(Sdk) is only here if something later needs to identify these -->
1213
<Using Include="Microsoft.Extensions.DependencyInjection" Sdk="Maui" />
1314
<Using Include="Microsoft.Maui" Sdk="Maui" />
@@ -30,7 +31,7 @@
3031
</ItemGroup>
3132

3233
<!-- Default .NET MAUI files-->
33-
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(EnableDefaultEmbeddedResourceItems)' == 'true' ">
34+
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(EnableDefaultEmbeddedResourceItems)' == 'true' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '@MAUI_DOTNET_VERSION@')) ">
3435
<MauiXaml Condition=" '$(EnableDefaultXamlItems)' == 'true' " Include="**\*.xaml" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />
3536
<MauiCss Condition=" '$(EnableDefaultCssItems)' == 'true' " Include="**\*.css" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />
3637
</ItemGroup>
@@ -41,7 +42,7 @@
4142
-->
4243

4344
<!-- Android -->
44-
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'android' and '$(MonoAndroidResourcePrefix)' != '' ">
45+
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'android' and '$(MonoAndroidResourcePrefix)' != '' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '@MAUI_DOTNET_VERSION@')) ">
4546
<AndroidResource Include="$(MonoAndroidResourcePrefix)/*/*.xml" />
4647
<AndroidResource Include="$(MonoAndroidResourcePrefix)/*/*.axml" />
4748
<AndroidResource Include="$(MonoAndroidResourcePrefix)/*/*.png" />
@@ -55,7 +56,7 @@
5556
</ItemGroup>
5657

5758
<!-- iOS -->
58-
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'ios' and '$(iOSProjectFolder)' != '' ">
59+
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'ios' and '$(iOSProjectFolder)' != '' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '@MAUI_DOTNET_VERSION@')) ">
5960
<None
6061
Include="$(iOSProjectFolder)Info.plist"
6162
Condition="Exists('$(iOSProjectFolder)Info.plist')"
@@ -90,7 +91,7 @@
9091
</ItemGroup>
9192

9293
<!-- MacCatalyst -->
93-
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'maccatalyst' and '$(MacCatalystProjectFolder)' != '' ">
94+
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'maccatalyst' and '$(MacCatalystProjectFolder)' != '' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '@MAUI_DOTNET_VERSION@')) ">
9495
<None
9596
Include="$(MacCatalystProjectFolder)Info.plist"
9697
Condition="Exists('$(MacCatalystProjectFolder)Info.plist')"
@@ -125,7 +126,7 @@
125126
</ItemGroup>
126127

127128
<!-- Windows -->
128-
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'windows' and '$(WindowsProjectFolder)' != '' ">
129+
<ItemGroup Condition=" '$(EnableDefaultMauiItems)' == 'true' and '$(SingleProject)' == 'true' and '$(TargetPlatformIdentifier)' == 'windows' and '$(WindowsProjectFolder)' != '' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '@MAUI_DOTNET_VERSION@')) ">
129130
<Manifest
130131
Include="$(ApplicationManifest)"
131132
Condition="Exists('$(ApplicationManifest)')" />

0 commit comments

Comments
 (0)