【问题标题】:How to exclude path from precompilation for AspNetCompiler in csproj如何从 csproj 中 AspNetCompiler 的预编译中排除路径
【发布时间】:2017-01-08 19:45:18
【问题描述】:

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

来自库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>

【问题讨论】:

    标签: c# asp.net msbuild aspnet-compiler


    【解决方案1】:

    您必须按照此博文https://matthewrwilton.wordpress.com/2017/03/12/excluding-node_modules-folder-from-asp-net-compilation/ 直接致电aspnet_compiler.exe 因为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 参数。

    【讨论】:

    • @Aixaz 这不是您要找的答案吗?
    • +1 使用这种方式调用 acpnet 编译器来编译包含 Angular 页面的 MVC 项目中的 cshtml 文件。默认情况下,它尝试使用系统中找不到的 c++ 编译器编译 node-modules 文件夹。
    • @Ilias.P 很高兴您发现它很有用。我遇到了同样的问题,想分享解决方案。
    猜你喜欢
    • 2018-02-06
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    相关资源
    最近更新 更多