Search

MvcBuildViews does not play well with one-click publish by Stephen Cleary

Active

30
0
Sign in
to vote
Type: Bug
ID: 556312
Opened: 5/1/2010 12:01:38 PM
Access Restriction: Public
5
Workaround(s)
16
User(s) can reproduce this bug
When MvcBuildViews is set to true, one-click publishing (at least to the file system) will only work one time. All future attempts fail with the message:

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Details (expand)

Product Language

English

Visual Studio Version

Visual Studio 2010

Operating System

Windows 7 Server

Operating System Language

English

Steps to Reproduce

File -> New Project -> ASP.NET MVC 2 Empty Web Application
Right-click project file -> Unload Project
Right-click project file -> Edit .csproj
Change <MvcBuildViews> to true and save
Right-click project file -> Reload project
Create Publish Settings (File System, c:\_test, Delete all existing files prior to publish)
Publish (succeeds)
Publish (fails); all future Publish or even Build commands will fail

Actual Results

Error message:
It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. C:\Users\stephen\Documents\Visual Studio 2010\Projects\MvcApplication5\MvcApplication5\obj\debug\package\packagetmp\web.config 18 MvcApplication5

Expected Results

Publishing and Building continue to work after the first Publish.
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey.

 

File Attachments
File Name Submitted By Submitted On File Size  
MvcApplication5.zip 5/1/2010 499 KB
Sign in to post a comment.
Posted by nygaardj on 3/3/2011 at 12:35 AM
Hi

We have 5-6 build configurations and every now and then when switching we have to clean out obj folder - a pain however manageable. However we just introduced config transformation into the solution, and now the error is persistent when compiling! The workaround we use is to insert a post-build event, where we delete the obj folder. ( rmdir /S /Q "$(ProjectDir)\obj" )
VS team, 10 month (at least) old bug - we need a fix.
Posted by Microsoft on 8/5/2010 at 9:34 AM
Hi,

These two features are unfortunately not compatible with each other. The problem happens because the publish feature copies the entire project to a temporary location within the project folder itself. Then the ASP.NET compiler runs and thinks that it needs to compile *everything* in the entire application, including the temporary copy. There is unfortunately no option to tell the compiler to ignore certain folders.

The recommended workaround is the one suggested in the comments, which is to do a full Clean of the solution (both Debug and Release, as you mention) before publishing.

There are potentially other workarounds, such as adding an additional command that runs before the ASP.NET compiler runs. If you edit the "csproj" (or "vbproj" for VB) file, you can add additional commands that will also trigger when the MvcBuildViews option is enabled. You can either use one of the built-in MSBuild commands that delete or move the temporary publish folder or you can use the more generic built-in command "Exec", which will run any arbitrary program that you want.

A list of available MSBuild commands is on MSDN, including in-depth documentation: http://msdn.microsoft.com/en-us/library/7z253716.aspx

Thanks,
The ASP.NET Team
Posted by Stephen Cleary on 5/3/2010 at 4:30 AM
@msony:

If you're switching between Debug and Release builds, then both Debug and Release builds need to be Clean'ed to work around this error message.
Posted by Msony on 5/3/2010 at 2:33 AM
ok, i deleted obj folder and it solved my problem :-)
Posted by Microsoft on 5/3/2010 at 1:33 AM
Thanks for your feedback. We were able to reproduce the issue you are seeing. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Msony on 5/2/2010 at 10:25 PM
the same problem, clean option does not solve this issue
Posted by Microsoft on 5/2/2010 at 4:07 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Stephen Cleary on 5/1/2010 at 12:05 PM
Clean the web project. Then the Publish command will work (once) again.
Posted by zihotki on 2/8/2011 at 7:02 PM
If you want to keep the MvcBuildViews as true, then you can add the following line underneath in your project file:

<BaseIntermediateOutputPath>[SomeKnownLocationIHaveAccessTo]</BaseIntermediateOutputPath>

And that path must be not in your project's folder.
Posted by nygaardj on 3/3/2011 at 12:36 AM
Insert post-build event, which delete the obj folder
rmdir /S /Q "$(ProjectDir)\obj"
Posted by Aidan Boyle on 3/27/2011 at 2:01 PM
Modify the MvcBuildViews target in your project file so that it depends on the targets that clean up the packaging files that Visual Studio has created. These targets are included in web application projects automatically.

All packaging files will be deleted every time that the MvcBuildViews target executes.

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'" DependsOnTargets="CleanWebsitesPackage;CleanWebsitesPackageTempDir;CleanWebsitesTransformParametersFiles;">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(MSBuildProjectDirectory)" />
</Target>
Posted by jrummell on 5/16/2011 at 10:27 AM
This is fixed in the MVC 3 Tools update. See Phil Hack's blog post for details:
http://haacked.com/archive/2011/05/09/compiling-mvc-views-in-a-build-environment.aspx