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?
See this, I guess you've to make IIS virtual directory names temp
to point to this application.
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.
<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.
and here:
https://stackoverflow.com/questions/2607428/msbuild-target-package-not-found/6413635#6413635Against 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With