How to exclude path from precompilation for AspNetCompiler in csproj
Asked Answered
H

1

11

example on command line that i use to exclude Admin path with -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

after run this result is fine. But when i translate to csproj scripts.

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

It does not parameter to exclude path from precompilation.

Currently command on csproj file

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'"> 
    <AspNetCompiler VirtualPath="Application.Web" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<Target Name="AfterBuild">
    <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
Havana answered 1/9, 2016 at 4:41 Comment(0)
J
10

You have to call the aspnet_compiler.exe directly as per this blogpost https://matthewrwilton.wordpress.com/2017/03/12/excluding-node_modules-folder-from-asp-net-compilation/ because the AspNetCompiler msbuild task doesn't have a property for exclusions.

Good thing is that you can call it with multiple exclusions, like so:

<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>

Just remember to use the -x parameter once per exclusion.

Josefina answered 2/2, 2018 at 12:3 Comment(3)
@Aixaz is this not the answer you were looking for?Josefina
+1 used this way to invoke acpnet compiler to compile cshtml files in an MVC project that included an angular page. By default it was trying to compile the node-modules folder with a c++ compiler which was unable to find in the system.Look
@Look Glad you found it useful. I had the same problem, and wanted to share the solution.Josefina

© 2022 - 2024 — McMap. All rights reserved.