62

我已从 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 构建下失败,并显示“无法加载类型 '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 构建问题?

4

9 回答 9

181

实际上,这个问题有更好的解决方案。我已经使用 VS/TFS 2010 对其进行了测试,但它也应该适用于 VS/TFS 2008。

<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

我将与 MVC 团队合作更新他们的项目模板以使用这种方法以及自定义目标(而不是覆盖 AfterBuild)。

我发表了一篇关于如何在 TFS Build 2010 中为 ASP.NET MVC 项目打开编译时视图检查的博客文章。

于 2010-04-19T20:53:36.557 回答
17

问题源于这样一个事实,即在 ASP.NET MVC 项目的 AfterBuild 目标中使用的 AspNetCompiler MSBuild 任务期望引用 Web 项目的 bin 文件夹中的 dll。

在桌面构建中,bin 文件夹是您在源代码树下所期望的位置。

但是,TFS Teambuild 会将源代码的输出编译到构建服务器上的不同目录。当 AspNetCompiler 任务启动时,它找不到 bin 目录来引用所需的 DLL,并且您会收到异常。

解决方法是将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 构建服务器上编译视图。

于 2009-07-08T14:24:50.383 回答
3

当我构建我们的 web .csproj 时,Jim Lamb 的解决方案对我们不起作用

/p:UseWPP_CopyWebApplication=true;PipelineDependsOnBuild=False

因为目标正在执行AfterBuild并且应用程序还没有被复制到WebProjectOutputDir。(顺便说一句,我将这些属性传递给 web 项目构建,因为我希望构建创建一个 OutDir 文件夹,其中只有我的二进制文件和适合压缩的 cshtml 文件,即不是就地构建)

为了解决这个问题并尊重他最初目标的意图,我做了以下事情:

<PropertyGroup>
    <OnAfter_WPPCopyWebApplication>
        MvcBuildViews;
    </OnAfter_WPPCopyWebApplication>
</PropertyGroup>

<Target Name="MvcBuildViews" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
于 2012-11-27T17:07:21.600 回答
1

我假设您的意思是您更改了 .csproj 文件中的以下设置:

<MvcBuildViews>true</MvcBuildViews>

不应触及您在问题中发布的设置。如果它可以在您的本地机器上运行,那么显然您可以预先构建一个 ASP.NET MVC 应用程序。

我认为您需要跟踪 TFS 构建环境和本地 VS 机器之间的不同之处。也许它正在使用不同版本的 MsBuild 或其他东西。

尝试使用详细输出执行两个构建并比较两者以查看有什么不同。

于 2009-04-20T16:14:29.813 回答
0

我们仍在对此进行测试,但您似乎可以将标签集中的 false/true 移动到您的 DEBUG 构建版本的属性组中,您仍然可以将其设置为 true 并且 MSBuild 将编译(假设 MSBuild TfsBuild.proj文件设置为使用除调试配置以外的其他内容)。您将需要使用记事本编辑 csproj 文件来完成此操作。

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <MvcBuildViews>true</MvcBuildViews>
    ....

您需要将 MVCBuildViews 标记从上面的默认属性组移动到调试配置属性组(下面)。同样,当我们获得 TFS / MSBuild 设置时,我将尝试将我们添加到 TFS 中的 TFSBuild.proj 文件中的步骤发布。

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <MvcBuildViews>true</MvcBuildViews>
    <DebugSymbols>true</DebugSymbols>
    ....
于 2009-05-28T19:15:33.933 回答
0

这个问题似乎与这里讨论的问题相似:http: //blogs.msdn.com/aaronhallberg/archive/2007/07/02/team-build-and-web-deployment-projects.aspx 似乎调用了 aspnet_compiler .exe 无法找到二进制文件,因为它们不在构建机器上 MVC 项目的 bin 文件夹中。我还没有想出解决办法。

于 2009-06-04T04:28:03.593 回答
0

接受的答案对我不起作用。$(PublishDir) 参数未指向正确的位置。相反,我不得不使用:

  <Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler Condition="'$(IsDesktopBuild)' != 'false'" VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
    <AspNetCompiler Condition="'$(IsDesktopBuild)' == 'false'" VirtualPath="temp" PhysicalPath="$(OutDir)\_PublishedWebsites\$(ProjectName)" />
  </Target>
于 2009-08-06T08:12:26.267 回答
0

我的源代码管理中有一些旧文件夹在解决方案中不可见。

于 2011-02-16T20:19:13.537 回答
-6

您不能预先构建 ASP.NET MVC 应用程序。

于 2009-04-16T17:34:52.383 回答