我正在使用 RazorPages(在 ASP.NET Core 6 上)和 css 隔離功能。css 檔案在 生成obj/{Debug,Release}/net6.0/scopedcss/Pages/,并在執行dotnet publish.
我也使用 Webpack,所以我不需要發布那些 css 檔案(它們已經被 Webpack 捆綁了)。
我添加了所有這些的變體,Project.csproj但沒有成功:
<ItemGroup>
<Content Remove="obj/*/*/scopedcss/**/*" />
</ItemGroup>
<ItemGroup>
<Content Remove="*.cshtml.rz.scp.css" />
</ItemGroup>
<ItemGroup>
<None Remove="obj/*/*/scopedcss/**/*" />
</ItemGroup>
<ItemGroup>
<Compile Remove="*.cshtml.rz.scp.css" />
</ItemGroup>
<ItemGroup>
<PublishedFiles Remove="obj/*/*/scopedcss/**/*" />
</ItemGroup>
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);obj/*/*/scopedcss/**/*</DefaultItemExcludes>
</PropertyGroup>
如何從已發布的輸出中排除 css 隔離資產?
更新
我找到了控制它的 msbuild 東西,但不知道如何防止它在發布期間復制。SDK 中的這個位會匯入功能的 msbuild 目標,它們是here和here。
uj5u.com熱心網友回復:
這暫時不受支持,但將在 net7 中實作(希望如此)。
使用“私有”屬性的解決方法:
<Target Name="_RemoveScopedCssFiles" AfterTargets="_AddGeneratedScopedCssFiles">
<ItemGroup>
<StaticWebAsset Remove="@(StaticWebAsset)" Condition="$([System.String]::Copy('%(Identity)').EndsWith('rz.scp.css'))">
</ItemGroup>
</Target>
我會猶豫是否使用它,因為它不是公共合同/界面的一部分。不過它可能適合你。
一個緩慢而丑陋但安全的解決方法是讓運行時發布檔案,然后洗掉它們:
<Target Name="DeleteScopedCssAssetsAfterPublish" AfterTargets="AfterPublish">
<RemoveDir Directories="$(PublishUrl)/wwwroot/Pages" />
</Target>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/485979.html
標籤:。网 asp.net 核心 网页包 构建 dotnet-发布
上一篇:如何在Drupal專案中使用Webpack設定實時重新加載和資產編譯?
下一篇:熱模塊更換總是完全重新加載
