如何让 Team Build 2010 将 Web 应用程序发布为不可更新?

发布于 2025-01-08 18:47:34 字数 1397 浏览 0 评论 0原文

我正在尝试将我们的构建从运行自定义 .msbuild 文件的 CruiseControl.NET 切换到 Team Build 2010。正在编译的应用程序是一个包含许多项目的 VS2008 解决方案,其中两个是 Web 项目。

使用 DefaultTemplate.xaml,这两个 Web 项目似乎已部署到 Binaries\_PublishedWebsites\(ProjectName)。默认位置就可以了。但是,输出目录的内容似乎是可更新的,就像使用 -u 调用 aspnet_compiler.exe 一样,或者就像 MSBuild 一样。 任务与 Updateable="true" 一起使用。那么,有两个问题:

  1. 如何使 Team Build 向 _PublishedWebsites 目录生成不可更新的输出?
  2. 如何设置 IIS VirtualPath,就像在 MSBuild 任务中执行以下操作一样:

    
    

我在早期的故障排除中发现,让 IIS 6 为使用其编译的 Web 服务提供服务的唯一方法不可更新模式下的 aspnet_compiler.exe 是在命令中指定虚拟路径,这就是我询问 #2 的原因。

编辑:

看到到目前为止的一个答案,我意识到我应该更清楚问题是什么。我意识到,如果我可以在 MSBuild 中执行某些操作,我就可以从构建模板中调用 MSBuild。但是,我想更多地了解如何更改将输出复制到 _PublishedWebsites 目录的情况。 “查找复制网站并更改它的任务”效果很好,只是我看不到实际将输出复制到 _PublishedWebsites 中的内容。我真正想做的是修改模板中完成此操作的步骤。

构建日志引用了一个名为 _CopyWebApplication 的编译目标,该目标似乎负责复制 Web 应用程序所需的文件。但是,我不确定如何修改此编译目标,因为我在构建模板中的任何位置以及解决方案中的任何文件中都没有看到它。此外,无论运行 _CopyWebApplication 似乎都只针对 Web 应用程序项目运行,而不是解决方案中的许多其他项目。这是一件好事,只不过我不知道决定是否使用_CopyWebApplication的逻辑在哪里。

也许我缺少一些默认的 MSBuild 文件?我可以使用一些构建参数?如何更改上述构建步骤?

I'm trying to switch our build from CruiseControl.NET running a custom .msbuild file to Team Build 2010. The application being compiled is a VS2008 solution with numerous projects, two of which are web projects.

Using DefaultTemplate.xaml, it appears that the two web projects are deployed to Binaries\_PublishedWebsites\(ProjectName). That default location is fine. However, the contents of the output directories appear to be updateable, as though aspnet_compiler.exe was called with -u, or as though an MSBuild <AspNetCompiler> task was used with Updateable="true". So, two questions:

  1. How do I make Team Build produce non-updateable output to the _PublishedWebsites directory?
  2. How can I also set the IIS VirtualPath as if I was doing the following in an MSBuild task:

    <AspNetCompiler Clean="true" Force="true" VirtualPath="/My-IIS-Virtual-Path" />
    

I have found in earlier troubleshooting that the only way I can get IIS 6 to serve a web service compiled with aspnet_compiler.exe in non-updateable mode is to specify the virtual path in the command, which is why I am asking about #2.

Edit:

Upon seeing the one answer thus far, I realized I should have been much clearer about what the issue is. I realize that, if I can do something in MSBuild, I can just call MSBuild from the build template. However, I am wondering a little more about how change what happens to copy the output to the _PublishedWebsites directory. "Find the task that copies the website and change it" would work well, except that I don't see what is actually copying the output into _PublishedWebsites. What I'm really wanting to do is to modify the step in the template that accomplishes this.

The build log references a compile target called _CopyWebApplication that appears to do the work of copying the files needed for a web application. However, I am unsure how to modify this compile target, as I do not see it anywhere in the build template nor in any file in the solution. Further, whatever runs _CopyWebApplication appears to be running it only for web application projects, not the many other projects in the solution. This is a good thing, except that I do not know where the logic exists that determines whether to use _CopyWebApplication.

Maybe there is some default MSBuild file that I am missing? Some build parameter that I could be using? How do I alter the aforementioned build step?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

偷得浮生 2025-01-15 18:47:34

_CopyWebApplication 目标的所有逻辑都定义在:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets

目标本身相当简单,但它带有一堆先决条件:

<Target Name="_CopyWebApplication" 
        Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'" 
        DependsOnTargets="$(_CopyWebApplicationDependsOn)">

  <CallTarget Condition="'$(OnAfter_CopyWebApplication)' != ''" Targets="$(OnAfter_CopyWebApplication)" RunEachTargetSeparately="true" />

</Target>

一旦到达所需的标志集,您就可以控制该过程。以下是默认值:

<WebProjectOutputDirInsideProjectDefault>True</WebProjectOutputDirInsideProjectDefault>
<WebProjectOutputDirInsideProjectDefault  Condition="('$(OutDir)' != '$(OutputPath)') Or ('$(IsDesktopBuild)' == 'False')" >False</WebProjectOutputDirInsideProjectDefault>
<DisableLinkInCopyWebApplicaton Condition="'$(DisableLinkInCopyWebApplicaton)'==''">False</DisableLinkInCopyWebApplicaton>
<Disable_CopyWebApplication Condition="'$(Disable_CopyWebApplication)' == ''">False</Disable_CopyWebApplication>
<UseWPP_CopyWebApplication Condition="'$(UseWPP_CopyWebApplication)' == ''">False</UseWPP_CopyWebApplication>
<CleanWebProjectOutputDir>True</CleanWebProjectOutputDir>
<CleanWebProjectOutputDir Condition="$(WebProjectOutputDirInsideProject)" >False</CleanWebProjectOutputDir>

All logic of the _CopyWebApplication target is defined in:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets

The target itself is rather simple but it carries a bunch of pre-conditions:

<Target Name="_CopyWebApplication" 
        Condition="!$(Disable_CopyWebApplication) And '$(OutDir)' != '$(OutputPath)'" 
        DependsOnTargets="$(_CopyWebApplicationDependsOn)">

  <CallTarget Condition="'$(OnAfter_CopyWebApplication)' != ''" Targets="$(OnAfter_CopyWebApplication)" RunEachTargetSeparately="true" />

</Target>

You can control the process once getting to the desired set of flags. The following are the defaults:

<WebProjectOutputDirInsideProjectDefault>True</WebProjectOutputDirInsideProjectDefault>
<WebProjectOutputDirInsideProjectDefault  Condition="('$(OutDir)' != '$(OutputPath)') Or ('$(IsDesktopBuild)' == 'False')" >False</WebProjectOutputDirInsideProjectDefault>
<DisableLinkInCopyWebApplicaton Condition="'$(DisableLinkInCopyWebApplicaton)'==''">False</DisableLinkInCopyWebApplicaton>
<Disable_CopyWebApplication Condition="'$(Disable_CopyWebApplication)' == ''">False</Disable_CopyWebApplication>
<UseWPP_CopyWebApplication Condition="'$(UseWPP_CopyWebApplication)' == ''">False</UseWPP_CopyWebApplication>
<CleanWebProjectOutputDir>True</CleanWebProjectOutputDir>
<CleanWebProjectOutputDir Condition="$(WebProjectOutputDirInsideProject)" >False</CleanWebProjectOutputDir>
↘人皮目录ツ 2025-01-15 18:47:34

KMoraz 为我指明了正确的方向,我还必须做一些事情才能使其发挥作用。我真的不想编辑内置的 .targets 文件,因为这会给任何其他不知道我做了什么的开发人员带来一些维护问题。我最终编辑了两个 Web 应用程序的 .csproj 文件,从文件末尾附近的默认 元素开始,到默认元素之前结束 元素:

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <!-- Since this Import serves no real purpose in VS2008 under Team Build, I'm commenting it out to remove
       a _CopyWebApplication step that we don't want.
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
  -->
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <!-- Now, for Team Build, do the AspNetCompile steps ourselves. -->
  <PropertyGroup>
      <WebProjectOutputDir Condition="'$(OutDir)' != '$(OutputPath)'">$(OutDir)_CompiledWebsites\$(MSBuildProjectName)</WebProjectOutputDir>
  </PropertyGroup>
  <PropertyGroup>
      <BuildDependsOn>
          $(BuildDependsOn);
          DoAspNetCompile
      </BuildDependsOn>
  </PropertyGroup>
  <Target Name="DoAspNetCompile" Condition="'$(CompileWebsites)' == 'True' And '$(OutDir)' != '$(OutputPath)'">
      <Message Text="Performing AspNetCompile step for $(MSBuildProjectName)" />
      <Message Text="Output will have IIS virtual directory '$(IISVirtualPath)'" />
      <Message Text="ProjectDir is $(ProjectDir)" />
      <Message Text="IsDebug is $(IsDebug)" />
      <RemoveDir Directories="$(WebProjectOutputDir)" ContinueOnError="true" />
      <MakeDir Directories="$(WebProjectOutputDir)" />
      <!-- We need the /bin directory, populated with some DLLs and PDBs -->
      <CreateItem Include="$(OutDir)*.dll;$(OutDir)*.pdb">
          <Output TaskParameter="Include" ItemName="BinariesToCopy" />
      </CreateItem>
      <Copy DestinationFolder="$(ProjectDir)\bin" SourceFiles="@(BinariesToCopy)" />
      <AspNetCompiler Clean="True" Force="True" Debug="$(IsDebug)" Updateable="False" VirtualPath="$(IISVirtualPath)" PhysicalPath="$(ProjectDir)" TargetPath="$(WebProjectOutputDir)" />
  </Target>

一些解释:

  1. 正如您所看到的,它在 .csproj 文件中说,C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets 默认情况下正在使用。我之前没有意识到 MSBuild 就是这样知道使用 .targets 文件的。由于在VS2008下不使用目标文件的_CopyWebApplication目标的唯一方法就是不使用该文件,并且由于VS2010版本确实对我没有帮助,所以我只是注释掉了导入。
  2. 为了区分我的输出和默认输出,我将输出目录的名称更改为 _CompiledWebsites 而不是 _PublishedWebsites
  3. 我添加了 元素,以便修改扩展点的任何其他项目文件都不会禁用我的目标。
  4. 我确实要求将 CompileWebsites 设置为 true (使用类似于传递给 MSBuild 的 /p:CompileWebsites=true 参数,尽管在 Team Build 中,还有其他方法可以如果需要,可以完成此操作)。这样,默认的本地构建就不会受到影响。
  5. 元素用于调试。我已在文件顶部附近的配置中将 $(IsDebug) 设置为 True 或 False。除了普通的“调试”和“发布”之外,我们还有许多配置,因此这个标志是必要的,这样我就可以告诉 AspNetCompiler 是否包含调试符号。 $(IISVirtualPath) 也在文件顶部附近的配置中设置。 IIS 6 必须提供以这种方式编译的 Web 服务。
  6. AspNetCompiler 找不到 Team Build 默认放置的预编译二进制文件,因此我将它们复制到项目的 bin\ 目录,其中 AspNetCompiler期望找到他们。
  7. 我无需对 Team Build 中的 .xaml 模板执行任何特殊操作即可使其正常工作。我确实必须确保构建定义包含 /p:CompileWebsites=True 参数。为此,请右键单击“团队资源管理器”窗口中的构建定义(在团队项目下的“构建”下),单击“处理”,展开“3. 高级”条目,然后输入 /p:CompileWebsites=True< /code> 标记为“MSBuild Arguments”的行。

如果我有两个以上的项目需要此构建配置,我可能会使用 DoAspNetCompile 目标创建一个文件并导入该文件。

KMoraz pointed me in the right direction, and I had to do a few more things to get this working. I really did not want to edit the built-in .targets files, since that would create some maintenance problems down the line for any other developer who did not know what I did. I ended up editing the .csproj files for the two web applications to this, starting with the default <Import> element near the end of the file and ending before the default <ProjectExtensions> element:

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <!-- Since this Import serves no real purpose in VS2008 under Team Build, I'm commenting it out to remove
       a _CopyWebApplication step that we don't want.
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />
  -->
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <!-- Now, for Team Build, do the AspNetCompile steps ourselves. -->
  <PropertyGroup>
      <WebProjectOutputDir Condition="'$(OutDir)' != '$(OutputPath)'">$(OutDir)_CompiledWebsites\$(MSBuildProjectName)</WebProjectOutputDir>
  </PropertyGroup>
  <PropertyGroup>
      <BuildDependsOn>
          $(BuildDependsOn);
          DoAspNetCompile
      </BuildDependsOn>
  </PropertyGroup>
  <Target Name="DoAspNetCompile" Condition="'$(CompileWebsites)' == 'True' And '$(OutDir)' != '$(OutputPath)'">
      <Message Text="Performing AspNetCompile step for $(MSBuildProjectName)" />
      <Message Text="Output will have IIS virtual directory '$(IISVirtualPath)'" />
      <Message Text="ProjectDir is $(ProjectDir)" />
      <Message Text="IsDebug is $(IsDebug)" />
      <RemoveDir Directories="$(WebProjectOutputDir)" ContinueOnError="true" />
      <MakeDir Directories="$(WebProjectOutputDir)" />
      <!-- We need the /bin directory, populated with some DLLs and PDBs -->
      <CreateItem Include="$(OutDir)*.dll;$(OutDir)*.pdb">
          <Output TaskParameter="Include" ItemName="BinariesToCopy" />
      </CreateItem>
      <Copy DestinationFolder="$(ProjectDir)\bin" SourceFiles="@(BinariesToCopy)" />
      <AspNetCompiler Clean="True" Force="True" Debug="$(IsDebug)" Updateable="False" VirtualPath="$(IISVirtualPath)" PhysicalPath="$(ProjectDir)" TargetPath="$(WebProjectOutputDir)" />
  </Target>

Some explanations:

  1. It says right in the .csproj file, as you can see, that C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets is in use by default. I did not realize previously that was how MSBuild knew to use that .targets file. Since the only way not to use the target file's _CopyWebApplication target under VS2008 is not to use the file, and since the VS2010 version really did not help me either, I just commented out the import.
  2. Just to distinguish my output from the default, I changed the name of the output directory to _CompiledWebsites instead of _PublishedWebsites.
  3. I added the <BuildDependsOn> element so that any other project files down the road that modify the extension points do not disable my target.
  4. I do require that CompileWebsites is set to true (using something like the /p:CompileWebsites=true parameter passed to MSBuild, though within Team Build, there are also other ways to accomplish this if desired). That way, the default local build is unaffected.
  5. The <Message> elements are for debugging. I have set $(IsDebug) to True or False in the configurations near the top of the file. We have many configurations besides vanilla "Debug" and "Release", so this flag was necessary so I could tell AspNetCompiler whether to include debugging symbols. $(IISVirtualPath) is also set in the configurations near the top of the file. It is necessary so that IIS 6 will serve a web service compiled in this manner.
  6. AspNetCompiler cannot find the precompiled binaries where Team Build puts them by default, so I copy them to the bin\ directory of the project, where AspNetCompiler expects to find them.
  7. I did not have to do anything special with the .xaml template in Team Build to get this to work. I did have to ensure that the build definition includes the /p:CompileWebsites=True parameter. To accomplish this, right-click the build definition in the Team Explorer window (under Builds under your team project), click "Process", expand the "3. Advanced" entry, and enter /p:CompileWebsites=True for the line labeled "MSBuild Arguments".

If I had more than two projects that needed this build configuration, I would probably create a file with the DoAspNetCompile target and import that file.

居里长安 2025-01-15 18:47:34

TFS 2010 Build 中的 DefaultTemplate.xaml 仍使用 MSBuild 来生成项目,因此,如果您列出的两件事可以使用 MSBuild.exe 完成,则也可以使用 2010 生成过程来完成。您所需要做的就是将所需的 MSBuild 参数添加到构建定义的“进程参数”中。有关更新生成定义的更多详细信息,请访问 MSDN

The DefaultTemplate.xaml in TFS 2010 Build still uses MSBuild to build your projects, so if the two things that you list can be done with MSBuild.exe, they can be done with the 2010 build process. All you need to do is to add the MSBuild arguments you want to the Process Parameters of your build definition. More details about updating your build definition can be found on MSDN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文