16

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?

ajbeaven
  • 9,265
  • 13
  • 76
  • 121
  • I'm having this same problem too, so I've started a bounty. – John Rutherford Feb 20 '17 at 22:40
  • Adding `..\bin` after `true` element works in most occurences, often apply when another `web.config` file has been present in `obj` directory. – Tetsuya Yamamoto Feb 24 '17 at 09:22
  • @TetsuyaYamamoto That didn't help. – John Rutherford Feb 28 '17 at 14:58
  • I have a similar issue. But I notice if I manually pass -p to the aspnet_compiler.exe like below, it'll work. However, I don't know how to tell the project file to do that. C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v temp -p path-to-output – Ray Cheng Apr 28 '17 at 22:45

2 Answers2

3

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.

  • I had to do this on my developing machine. The two needed folders I obtained from ``C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\`` – Jack Miller Oct 26 '22 at 05:41
  • Unfortunately, it worked only once. The second compile run ended with the same error again. – Jack Miller Oct 26 '22 at 05:49
2

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

SACn
  • 1,862
  • 1
  • 14
  • 29
  • 1
    While that probably would solve the issue, I don't think it should be necessary. Nor is it practical to require all of our developers to set this up and to set it up on our build servers. – John Rutherford Feb 28 '17 at 14:51