Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Enable Razor files to be visible in Solution Explorer because they are not Content files in .NET MAUI projects -->
<ItemGroup>
<AvailableItemName Include="RazorComponent"/>
</ItemGroup>

<!-- Prevent Razor files from being packaged as bundle resources in iOS/MacCatalyst targets by declaring them
as RazorComponent instead of Content. -->
<ItemGroup Condition="'$(DesignTimeBuild)' != 'true'">
<Content Remove="**\*.razor" />
<RazorComponent Include="**\*.razor" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<!-- Ensure global.json isn't published with the app. -->
<ItemGroup>
<Content Update="global.json" PublishFolderType="None" />
</ItemGroup>

<PropertyGroup>
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
<StaticWebAssetProjectMode>Root</StaticWebAssetProjectMode>
</PropertyGroup>

<Target Name="ConvertStaticWebAssetsToMauiAssets"
BeforeTargets="GetMauiItems;ResizetizeCollectItems;_CollectBundleResources;_CollectHotRestartBundleResources;_CheckForContent"
DependsOnTargets="ResolveProjectReferences;StaticWebAssetsPrepareForRun;StaticWebAssetsPrepareForPublish;LoadStaticWebAssetsPublishManifest">

<ComputeStaticWebAssetsTargetPaths Assets="@(StaticWebAsset)" PathPrefix="wwwroot">
<Output TaskParameter="AssetsWithTargetPath" ItemName="_MauiStaticWebAssetWithTargetPath" />
</ComputeStaticWebAssetsTargetPaths>

<ItemGroup>
<MauiAsset Include="%(_MauiStaticWebAssetWithTargetPath.Identity)">
<Link>%(_MauiStaticWebAssetWithTargetPath.TargetPath)</Link>
<TargetPath>%(_MauiStaticWebAssetWithTargetPath.TargetPath)</TargetPath>
</MauiAsset>
</ItemGroup>

<!-- Update Content files that are managed by the Razor SDK to opt out of iOS and Android content-checks -->
<ItemGroup>
<!-- .razor.css scoped css files -->
<_ContentNotScopedCssFiles Include="@(Content)" Exclude="@(ScopedCssInput)" />
<_ContentToUpdate Include="@(Content)" Exclude="@(_ContentNotScopedCssFiles)" />

<!-- .razor files -->
<_ContentToUpdate Include="@(Content->WithMetadataValue('Extension', '.razor'))" />

<Content Remove="@(_ContentToUpdate)" />
<Content Include="@(_ContentToUpdate)" ExcludeFromContentCheck="true" PublishFolderType="None" />

<!-- Remove the items in AppDesignerFolder ("Properties", by default) so they don't get copied to the output directory -->
<Content Remove="$(AppDesignerFolder)\**" Condition="'$(AppDesignerFolder)' != ''" />
</ItemGroup>

</Target>

<Target Name="_RemoveStaticWebAssetsDevelopmentManifest" BeforeTargets="GetCopyToOutputDirectoryItems">
<!-- Remove the development manifest from the output since its not used and it will otherwise get incorrectly loaded in production. -->
<ItemGroup>
<ContentWithTargetPath Remove="$(StaticWebAssetDevelopmentManifestPath)" />
</ItemGroup>
</Target>

<!-- Targets temporarily remove Content items in various folders so that they don't conflict with iOS/MacCatalyst SDK tasks -->
<Target Name="HideContentFromiOSBundleResources" BeforeTargets="_CollectBundleResources">
<ItemGroup>
<!-- Find all files outside the wwwroot folder -->
<_NonWWWRootContent Include="@(Content)" Exclude="wwwroot/**/*" />
<!-- Create a list of all content that *is* in the wwwroot folder (to preserve ItemGroup metadata) -->
<_TemporaryHiddenContent Include="@(Content)" Exclude="@(_NonWWWRootContent)" />
<!-- Add Scoped CSS files in the app to the list of hidden items -->
<_TemporaryHiddenContent Include="Components\**\*.razor.css" />
<_TemporaryHiddenContent Include="Pages\**\*.razor.css" />
<_TemporaryHiddenContent Include="Shared\**\*.razor.css" />
<!-- Temporarily remove the items -->
<Content Remove="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>
<Target Name="RestoreHiddeniOSContent" AfterTargets="_CollectBundleResources" BeforeTargets="ResolveCurrentProjectStaticWebAssetsInputs">
<ItemGroup>
<!-- Restore the previously removed Content items -->
<Content Include="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>

<!-- Handle hiding and restoring <Content /> from the iOS build in hot reload scenarios. -->
<Target Name="HideContentFromiOSHotRestartBundleResources" BeforeTargets="_CollectHotRestartBundleResources">
<ItemGroup>
<!-- Find all files outside the wwwroot folder -->
<_NonWWWRootContent Include="@(Content)" Exclude="wwwroot/**/*" />
<!-- Create a list of all content that *is* in the wwwroot folder (to preserve ItemGroup metadata) -->
<_TemporaryHiddenContent Include="@(Content)" Exclude="@(_NonWWWRootContent)" />
<!-- Add Scoped CSS files in the app to the list of hidden items -->
<_TemporaryHiddenContent Include="Components\**\*.razor.css" />
<_TemporaryHiddenContent Include="Pages\**\*.razor.css" />
<_TemporaryHiddenContent Include="Shared\**\*.razor.css" />
<!-- Temporarily remove the items -->
<Content Remove="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>
<Target Name="RestoreHiddeniOSHotRestartContent" AfterTargets="_CollectHotRestartBundleResources" BeforeTargets="ResolveCurrentProjectStaticWebAssetsInputs">
<ItemGroup>
<!-- Restore the previously removed Content items -->
<Content Include="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>

<!-- Targets temporarily remove Content items in various folders so that they don't conflict with Android SDK tasks -->
<Target Name="HideContentFromAndroidCheck" BeforeTargets="_CheckForContent">
<ItemGroup>
<_TemporaryAndroidHiddenContent Include="@(Content)" />
<Content Remove="@(Content)" />
</ItemGroup>
</Target>

<!-- Restore hidden Content items for Android -->
<Target Name="RestoreHiddenAndroidContent" AfterTargets="_CheckForContent">
<ItemGroup>
<Content Include="@(_TemporaryAndroidHiddenContent)" />
</ItemGroup>
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -1,124 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Enable Razor files to be visible in Solution Explorer because they are not Content files in .NET MAUI projects -->
<ItemGroup>
<AvailableItemName Include="RazorComponent"/>
</ItemGroup>
<!-- Conditionally import the actual targets only for application projects -->
<Import Project="Microsoft.AspNetCore.Components.WebView.Maui.Sdk.targets"
Condition="'$(OutputType)' == 'Exe' OR '$(OutputType)' == 'WinExe' OR '$(AndroidApplication)' == 'True' OR '$(ImportMicrosoftAspNetCoreComponentsWebViewMauiTargets)' == 'True'" />

<!-- Prevent Razor files from being packaged as bundle resources in iOS/MacCatalyst targets by declaring them
as RazorComponent instead of Content. -->
<ItemGroup Condition="'$(DesignTimeBuild)' != 'true'">
<Content Remove="**\*.razor" />
<RazorComponent Include="**\*.razor" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<!-- Ensure global.json isn't published with the app. -->
<ItemGroup>
<Content Update="global.json" PublishFolderType="None" />
</ItemGroup>

<PropertyGroup>
<StaticWebAssetBasePath>/</StaticWebAssetBasePath>
<StaticWebAssetProjectMode>Root</StaticWebAssetProjectMode>
</PropertyGroup>

<Target Name="ConvertStaticWebAssetsToMauiAssets"
BeforeTargets="GetMauiItems;ResizetizeCollectItems;_CollectBundleResources;_CollectHotRestartBundleResources;_CheckForContent"
DependsOnTargets="ResolveProjectReferences;StaticWebAssetsPrepareForRun;StaticWebAssetsPrepareForPublish;LoadStaticWebAssetsPublishManifest">

<ComputeStaticWebAssetsTargetPaths Assets="@(StaticWebAsset)" PathPrefix="wwwroot">
<Output TaskParameter="AssetsWithTargetPath" ItemName="_MauiStaticWebAssetWithTargetPath" />
</ComputeStaticWebAssetsTargetPaths>

<ItemGroup>
<MauiAsset Include="%(_MauiStaticWebAssetWithTargetPath.Identity)">
<Link>%(_MauiStaticWebAssetWithTargetPath.TargetPath)</Link>
<TargetPath>%(_MauiStaticWebAssetWithTargetPath.TargetPath)</TargetPath>
</MauiAsset>
</ItemGroup>

<!-- Update Content files that are managed by the Razor SDK to opt out of iOS and Android content-checks -->
<ItemGroup>
<!-- .razor.css scoped css files -->
<_ContentNotScopedCssFiles Include="@(Content)" Exclude="@(ScopedCssInput)" />
<_ContentToUpdate Include="@(Content)" Exclude="@(_ContentNotScopedCssFiles)" />

<!-- .razor files -->
<_ContentToUpdate Include="@(Content->WithMetadataValue('Extension', '.razor'))" />

<Content Remove="@(_ContentToUpdate)" />
<Content Include="@(_ContentToUpdate)" ExcludeFromContentCheck="true" PublishFolderType="None" />

<!-- Remove the items in AppDesignerFolder ("Properties", by default) so they don't get copied to the output directory -->
<Content Remove="$(AppDesignerFolder)\**" Condition="'$(AppDesignerFolder)' != ''" />
</ItemGroup>

</Target>

<Target Name="_RemoveStaticWebAssetsDevelopmentManifest" BeforeTargets="GetCopyToOutputDirectoryItems">
<!-- Remove the development manifest from the output since its not used and it will otherwise get incorrectly loaded in production. -->
<ItemGroup>
<ContentWithTargetPath Remove="$(StaticWebAssetDevelopmentManifestPath)" />
</ItemGroup>
</Target>

<!-- Targets temporarily remove Content items in various folders so that they don't conflict with iOS/MacCatalyst SDK tasks -->
<Target Name="HideContentFromiOSBundleResources" BeforeTargets="_CollectBundleResources">
<ItemGroup>
<!-- Find all files outside the wwwroot folder -->
<_NonWWWRootContent Include="@(Content)" Exclude="wwwroot/**/*" />
<!-- Create a list of all content that *is* in the wwwroot folder (to preserve ItemGroup metadata) -->
<_TemporaryHiddenContent Include="@(Content)" Exclude="@(_NonWWWRootContent)" />
<!-- Add Scoped CSS files in the app to the list of hidden items -->
<_TemporaryHiddenContent Include="Components\**\*.razor.css" />
<_TemporaryHiddenContent Include="Pages\**\*.razor.css" />
<_TemporaryHiddenContent Include="Shared\**\*.razor.css" />
<!-- Temporarily remove the items -->
<Content Remove="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>
<Target Name="RestoreHiddeniOSContent" AfterTargets="_CollectBundleResources" BeforeTargets="ResolveCurrentProjectStaticWebAssetsInputs">
<ItemGroup>
<!-- Restore the previously removed Content items -->
<Content Include="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>

<!-- Handle hiding and restoring <Content /> from the iOS build in hot reload scenarios. -->
<Target Name="HideContentFromiOSHotRestartBundleResources" BeforeTargets="_CollectHotRestartBundleResources">
<ItemGroup>
<!-- Find all files outside the wwwroot folder -->
<_NonWWWRootContent Include="@(Content)" Exclude="wwwroot/**/*" />
<!-- Create a list of all content that *is* in the wwwroot folder (to preserve ItemGroup metadata) -->
<_TemporaryHiddenContent Include="@(Content)" Exclude="@(_NonWWWRootContent)" />
<!-- Add Scoped CSS files in the app to the list of hidden items -->
<_TemporaryHiddenContent Include="Components\**\*.razor.css" />
<_TemporaryHiddenContent Include="Pages\**\*.razor.css" />
<_TemporaryHiddenContent Include="Shared\**\*.razor.css" />
<!-- Temporarily remove the items -->
<Content Remove="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>
<Target Name="RestoreHiddeniOSHotRestartContent" AfterTargets="_CollectHotRestartBundleResources" BeforeTargets="ResolveCurrentProjectStaticWebAssetsInputs">
<ItemGroup>
<!-- Restore the previously removed Content items -->
<Content Include="@(_TemporaryHiddenContent)" />
</ItemGroup>
</Target>

<!-- Targets temporarily remove Content items in various folders so that they don't conflict with Android SDK tasks -->
<Target Name="HideContentFromAndroidCheck" BeforeTargets="_CheckForContent">
<ItemGroup>
<_TemporaryAndroidHiddenContent Include="@(Content)" />
<Content Remove="@(Content)" />
</ItemGroup>
</Target>

<!-- Restore hidden Content items for Android -->
<Target Name="RestoreHiddenAndroidContent" AfterTargets="_CheckForContent">
<ItemGroup>
<Content Include="@(_TemporaryAndroidHiddenContent)" />
</ItemGroup>
</Target>

</Project>
</Project>
Loading