Using VS 2008 Web Deployment Projects with ASP.NET MVC

限于喜欢 提交于 2019-12-12 08:11:29

问题


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'.


回答1:


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




回答2:


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.




回答3:


I've found it working for me.

When you say there are files missing, are you talking about the System.Web.Mvc files and such? You need to make sure in your web application that these references are set to copy locally.




回答4:


I have deployt succesfully to IIS6 using a Web Deployment Project. I had issues deploying to Server 2003 first, but in my case it realy was a problem of the stage-environment. I first deployt to a local IIS to check if it was a problem of the build or of the environment. I did not use config - replacement.

This is my build script:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe "D:\Projekte\NiceProjectName\source\NiceProjectName_Build\NiceProjectName_Build.wdproj" /t:Build /p:Configuration=Release 

Here is my wdp:

<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.21022</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{E5E14CEB-0BCD-4203-9A5A-34ABA9C717EA}</ProjectGuid>
    <SourceWebPhysicalPath>..\NiceProjectName</SourceWebPhysicalPath>
    <SourceWebProject>{3E632DB6-6DB3-4BD0-8CCA-12DE67165B48}|NiceProjectName\NiceProjectName.csproj</SourceWebProject>
    <SourceWebVirtualPath>/NiceProjectName.csproj</SourceWebVirtualPath>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>.\Debug</OutputPath>
    <EnableUpdateable>true</EnableUpdateable>
    <UseMerge>true</UseMerge>
    <SingleAssemblyName>NiceProjectName_Build</SingleAssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugSymbols>false</DebugSymbols>
    <OutputPath>..\..\deploy</OutputPath>
    <EnableUpdateable>false</EnableUpdateable>
    <UseMerge>true</UseMerge>
    <SingleAssemblyName>NiceProjectName</SingleAssemblyName>
  </PropertyGroup>
  <ItemGroup>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\WebDeployment\v9.0\Microsoft.WebDeployment.targets" />
</Project>


来源:https://stackoverflow.com/questions/578918/using-vs-2008-web-deployment-projects-with-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!