Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvcBuildViews true causes "'/temp' is not a valid IIS application" error

After setting MvcBuildViews to true in my .csproj file in order to have the views compile during build, I get the following error:

'/temp' is not a valid IIS application

I presume that the '/temp' that this is referring to is the path where the views will be compiled. Here's the relevant section in the .csproj file:

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

I use full IIS to serve up this MVC 5 website on my local machine (haven't tried this on a remote server yet). Do I need to set something up in IIS to make MvcBuildViews work correctly?

like image 489
ajbeaven Avatar asked Jun 12 '16 22:06

ajbeaven


2 Answers

See this, I guess you've to make IIS virtual directory names temp to point to this application.

like image 111
SACn Avatar answered Sep 25 '22 09:09

SACn


This is an obscure and head-scratching problem. As pointed out by John Rutherford above, it shouldn't be necessary and isn't practical to create a "temp" web app on all the build servers. This is a compile-time issue, not a run-time issue, so IIS shouldn't even be involved.

Here's the answer; there's a fair amount to it. Credit to the many other people who have also researched this in various ways.

I am using everything up to date as of July, 2021: visual studio 2019, new build server 2019 with latest build tools and updates from visual studio 2019 installer.

  1. The offending line in the .csproj is
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />

If you read the spec for the AspNetCompiler clause, you'll see that VirtualPath, while required, is only used if PhysicalPath isn't present. In fact, I verified that PhysicalPath wasn't present using this directive inside the MvcBuildViews target:

<Message Text="WebProjectOutputDir=$(WebProjectOutputDir)" />

and sure enough, WebProjectOutputDir was blank. That's the genesis of the misleading "/temp is not a valid IIS application" or "Failed to map the path /temp" error messages from ASPNETCOMPILER.

  1. The problem is that your build server doesn't have the right build targets to create a web deploy package. You can see this if you look at the output - you'll see it stop right after the build, with no output (or error message) for the web deploy package task. This has been described here:
https://stackoverflow.com/questions/6409549/web-deploy-packaging-not-working-on-my-build-server

and here:

https://stackoverflow.com/questions/2607428/msbuild-target-package-not-found/6413635#6413635

Against all reason, the only solution I found that worked consistently was to copy

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.0\Web

and

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications

to

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0

on the build server (yes, I'm using MSBuild 16, go figure).

It has also been suggested that adding the nuget package

MSBuild.Microsoft.VisualStudio.Web.targets

solves the problem. It does, but it's a pretty rough thing to have to do to every web project in a large system.

You shouldn't have to do this, of course, but at least you, the build server administrator, can fix it for everyone. I can't see this as anything other than a bug, or at best a miscommunication.

like image 39
Scott D. Carson Avatar answered Sep 26 '22 09:09

Scott D. Carson