有时,当我发布ASP.NET MVC应用程序并将文件复制到生产服务器时,我收到404错误。当我检查新发布的网站和旧网站之间的差异时,我发现缺少一些文件,包括App_global.asax.dll和App_global.asax.compiled。Web部署后,MVC应用程序失败并出现404错误
这发生在Visual Studio 2015和以前的版本中。以前的出版物是成功的,但这似乎是间歇性的。在构建过程中不会产生任何错误。通过MSBuild发布和通过Visual Studio发布都似乎有同样的问题。有些日子,这个系统会很好的建立起来。有些日子,它不会。当我在发布之前删除软件包目录的内容时,这似乎发生得最多。
一个简单的示例MSBuild命令。这是一个非常简单的一个站点.csproj文件。
MSBuild.exe \MyProject.csproj /p:DeployOnBuild=true;PublishProfile=Prod
的发布设定档:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<publishUrl>C:\packages\MyProject</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>False</EnableUpdateable>
<DebugSymbols>False</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
</PropertyGroup>
</Project>