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

Aix*_*asz 9 c# asp.net msbuild aspnet-compiler

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

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脚本时。

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

它没有参数从预编译中排除路径。

当前命令 csproj 文件

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

Tro*_*sen 8

您必须aspnet_compiler.exe按照此博客文章https://matthewrwilton.wordpress.com/2017/03/12/exclusive-node_modules-folder-from-asp-net-compilation/直接调用, 因为AspNetCompilermsbuild 任务没有属性为排除。

好消息是您可以使用多个排除项调用它,如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

请记住每次排除使用一次 -x 参数。