Error trying to create ASP MVC Views during build

I have an ASP MVC 4 project. It started as MVC 1, so it uses old-style ASPX / ASCX views. I want the views to compile at build time, mainly to check for compile-time errors (and also, importantly, the errors display directly in Visual Studio). I am developing Visual Studio Pro 2015 using IIS Express as a debug server.

As for msdn , Haacked, and questions here such as this I installed the following my .vbproj:

<MvcBuildViews>true</MvcBuildViews> 

and also in my .vbproj created task

 <Target Name="BuildViews" Condition="'$(MvcBuildViews)'=='true'" AfterTargets="Build"> <Message Importance="normal" Text="Precompiling views" /> <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" /> </Target> 

However, this causes an error when trying to create:

'/ temp' is not a valid IIS application.

As a file, it simply refers to ASPNETCOMPILER

I tried various alternatives like VirtualPath - I have a project configured to run as a subdirectory / local in dev, so I tried this and the site names from the configuration in the .vs folder and nothing works.

Should I change VirtualPath (and if so, what), or is there any other config that is missing for temp to work?

Edit

In addition, I get the same error when starting the MSBuild command prompt. For my real production systems, I have a script that builds using the MSBuild command line, then moves the embedded package to the product servers and deploys. Thus, when it is not created, IIS express (or IIS works) will not. Do you need a web server linked only to compile views?

Edit 2

I am confused by the need to use virtulPath and the obvious connection to the web server. Some of the suggested solutions include IIS configuration. IIS Express (which I use for debugging) doesn’t even work until a successful build, as I understand it? In any case, my application works in the virtual directory quite successfully (/ local in debug mode), but using this as a value does not work. If that matters, this is the corresponding part of applicationhost.config in the .vs folder in my project (I tried putting the same paths in the applciationhost.config file in Documents / IIS Express):

  <site name="CarWeb-Site" id="2"> <application path="/" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="C:\Users\adam.conway\Documents\My Web Sites\CarWeb-Site" /> </application> <application path="/local" applicationPool="Clr4IntegratedAppPool"> <virtualDirectory path="/" physicalPath="filesystem path to my project" /> </application> <bindings> <binding protocol="http" bindingInformation="*:57047:localhost" /> <binding protocol="http" bindingInformation="*:57047:*" /> </bindings> </site> 

Therefore, I really do not understand why just VirtualPath="/" does not work, since the virtual path is specified in these configurations.

While my main goal is to show display errors in Visual Studio (and I agree with the answer limited to this), this is also the case that I create for production environments using MSBuild on a machine that does not even have IIS installed.

+8
visual-studio asp.net-mvc asp.net-mvc-4 iis-express
source share
2 answers

AspNetCompiler calls aspnet_compiler.exe ( https://msdn.microsoft.com/en-us/library/ms229863.aspx?f=255&MSPPError=-2147217396 ). In the Visual Studio error list, calls to this exe appear as ASPNETCOMPILER.

I recommend that you enable the diagnostic level https://msdn.microsoft.com/en-us/library/jj651643.aspx , then find the assembly log for the aspnet_compiler.exe line and check which parameters (in particular, which path) are used when calling aspnet_compiler.exe. You can also copy from the log and manually call aspnet_compiler.exe in cmd.exe.

Most likely, the problem is in the PhysicalPath attribute, and not in VirtualPath, it seems that the VirtualPath attribute does not affect the assembly. Check out these answers:

  • VirtualPath in AspNetCompiler MSBuild's task - should it be equal to the final deployed virtual path?
  • Why do I need a VirtualPath property for an AspNetCompiler task

If you need separate paths for MSBuild and Visual Studio, you can use this method http://web4.codeproject.com/Articles/156989/Resolve-temp-global-asax-error-ASPPARSE-Could?display=Print

+3
source share

Based on @snautz answer, the line I use for me is

 <AspNetCompiler VirtualPath="/" PhysicalPath="$(ProjectDir)" /> 

Many of the online examples used $(ProjectDir)\..\$(ProjectName) as PhysicalPath , but I'm not sure why, since this just solves $(ProjectDir) ...

+1
source share

All Articles