我已经从ASP.NET MVC Beta升级到1.0,并对MVC项目进行了以下更改(如RC发行说明所述):

<Project ...>
  ...
  <MvcBuildViews>true</MvcBuildViews>
  ...
  <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
  </Target>
  ...
</Project>

虽然该构建在我们的本地开发盒上运行良好,但是在TFS 2008 Build上失败并显示“无法加载类型'xxx.MvcApplication'”,请参见以下构建日志:
...
using "AspNetCompiler" task from assembly "Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "AspNetCompiler"

  Command:
  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v temp -p D:\Builds\xxx\Continuous\TeamBuild\Sources\UI\xxx.UI.Dashboard\\..\xxx.UI.Dashboard
  The "AspNetCompiler" task is using "aspnet_compiler.exe" from "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe".
  Utility to precompile an ASP.NET application
  Copyright (C) Microsoft Corporation. All rights reserved.

/temp/global.asax(1): error ASPPARSE: Could not load type 'xxx.UI.Dashboard.MvcApplication'.
  The command exited with code 1.

Done executing task "AspNetCompiler" -- FAILED.
...

MVC 1.0安装在TFS上,并且在同一TFS服务器上的Visual Studio实例中构建该解决方案时即可编译。

如何解决此TFS Build问题?

最佳答案

问题源于以下事实:在ASP.NET MVC项目的AfterBuild目标中使用的AspNetCompiler MSBuild任务期望引用Web项目的bin文件夹中的dll。

在桌面版本中,bin文件夹位于源代码树下的预期位置。

但是,TFS Teambuild会将源的输出编译到构建服务器上的其他目录。当AspNetCompiler任务启动时,它找不到要引用所需DLL的bin目录,您将获得异常。

解决方案是将MVC项目的AfterBuild目标修改如下:

  <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler Condition="'$(IsDesktopBuild)' != 'false'" VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
    <AspNetCompiler Condition="'$(IsDesktopBuild)' == 'false'" VirtualPath="temp" PhysicalPath="$(PublishDir)\_PublishedWebsites\$(ProjectName)" />
  </Target>

通过此更改,您可以在台式机和TFS构建服务器上编译 View 。

09-30 14:07
查看更多