Visual Studio 2010 “Publish” does not copy Razor v

2019-02-04 06:41发布

问题:

When using the built-in Publish feature of Visual Studio 2010 with a web application that includes Razor views (.cshtml or .vbhtml), the publish service does not copy the Razor view files.

This occurs both on a local "File System" publish as well as a remote publish using Web Deploy, using the November 9 Release Candidate.

Are there any known workarounds?

回答1:

You need to set the build action to "Content" under properties.

Edit: You have to do this on each of the files that aren't being copied over.

Edit 2: I did some poking around, and found a forum posting over at msdn, sounds like you can edit the registry, or create a pkdef file.

http://social.msdn.microsoft.com/Forums/en/vsxprerelease/thread/c0212d15-96c4-455d-b7e1-d299c5ef384a



回答2:

(This answer is mostly if someone finds this through google etc)

As @Ted Ballou pointed out you need to change output type to Content. This can be quite cumbersome if you, like me, have 100+ files in different subfolders.

Especially since you can't update multiple files at once if there's a folder included in the selection.

Instead of changing through the GUI, open the project file and modify the settings directly.

In YourProject.csproj change items like:

<None Include="Views\Foo\Bar.cshtml />

to

<Content Include="Views\Foo\Bar.cshtml" />

I used the following Regular Expression to replace all files:

Search for: <None Include="(.+)\.cshtml" />

Replace with: <Content Include="$1.cshtml" />

Now Visual Studio should treat all your changed cshtml as Content on publish.