Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VS 2008 Web Deployment Projects with ASP.NET MVC

Has anyone got a Web Deployment Project to work with ASP.NET MVC? When I open the "deployed" project, a lot of the files are missing that MVC requires and makes it tough to Publish to the server with all the missing files in the project.

Or... Is there a better way than a Web Deployment Project to modify the Web.Config for MVC apps? I have differences (SMTP and connection strings) that need to be updated before uploading and Web Deployment Projects seem to be the right method.

Thanks as always!

Update: I am missing at least global.asax, global.asax.cs, and default.aspx.cs.

Update 2: Once I Publish, I get this error. Could not load type 'AppNamespace._Default'.

like image 751
Daniel A. White Avatar asked Feb 23 '09 19:02

Daniel A. White


People also ask

How do I open an ASP NET project in Visual Studio 2008?

In Visual Studio, on the File menu, select New Project, and then select the ASP.NET Web Application template. Click OK. Visual Studio opens to the Source view of the Default. aspx page so that you can edit it.

How do I deploy an ASP NET application from Visual Studio to app service?

In Solution Explorer, right-click on the project and click Publish. Visual Studio can create a new App Service resource, but this update will be published over the existing deployment. In the Pick a publish target dialog, select App Service from the list on the left, and then select Select Existing. Click Publish.

What is the difference between Web project and Web site in Visual Studio?

The simple answers are as follows: New Web Site - creates code behind pages that are compiled at the server when page is requested. New Web Project - creates pre-compiled pages into one or more assemblies (entire site even), and deployed on server.


2 Answers

I haven't set up a Deployment project yet with my mvc app but I've been using this technique outlined by Scott Hanselman and it works great.

Managing Multiple Configuration File Environments

like image 127
Mike Roosa Avatar answered Oct 21 '22 01:10

Mike Roosa


The 3 specific files you have listed are all compiled into the binary produced by your ASP.NET MVC web project. Open up your .csproj and you will see:

<Compile Include="Global.asax.cs">
  <DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Default.aspx.cs">
  <DependentUpon>Default.aspx</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>

Open up your binary in a tool such as Reflector and you will see the classes. Therefore you don't need to deploy them.

These MSBuild steps in the MVC .csproj render part of what the Web Deployment Project does (i.e. compiling a single binary for the site) redundant.

As for the token replacement you can either keep your Deployment project or probably copy the relevant MSBuilds steps from your .wdproj file into your .csproj file. This is not something I've done, but am shortly to try myself.

like image 36
user53419 Avatar answered Oct 21 '22 00:10

user53419