如何排除路径预编译的AspNetCompiler在csproj

本文关键字:编译 AspNetCompiler csproj 路径 何排除 排除 | 更新日期: 2023-09-27 18:04:57

命令行示例,我使用-x来排除Admin路径

C:'Users'Test>C:'Windows'Microsoft.NET'Framework'v4.0.30319'aspnet_compiler.exe -v /Application.Web -p D:'Application.Web -x /Application.Web/Admin

运行后,结果很好。但当我翻译成csproj脚本。

from lib https://msdn.microsoft.com/en-us/library/ms164291.aspx

不指定从预编译中排除path。

当前命令在csproj文件

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'"> 
    <AspNetCompiler VirtualPath="Application.Web" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<Target Name="AfterBuild">
    <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>

如何排除路径预编译的AspNetCompiler在csproj

您必须直接调用aspnet_compiler.exe按照这个博客帖子https://matthewrwilton.wordpress.com/2017/03/12/excluding-node_modules-folder-from-asp-net-compilation/因为AspNetCompiler msbuild任务没有排除属性。

好的是你可以用多个排除来调用它,像这样:

<PropertyGroup>
    <exclusion1>some/path</exclusion1>
    <exclusion2>another/path</exclusion2>
</PropertyGroup>
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <Exec Command="$(MSBuildFrameworkToolsPath)aspnet_compiler.exe -v temp -p $(WebProjectOutputDir) -x $(exclusion1) -x $(exclusion2)"/>
</Target>

只要记住在每次排除时使用-x参数。