简体   繁体   English

如何在Visual Studio 2008中自动发布构建网站?

[英]How to automatically publish a website on build in Visual Studio 2008?

I want to be able to automatically publish to a local folder each time a web asp.net mvc 2 project is built. 我希望每次构建web asp.net mvc 2项目时都能自动发布到本地文件夹。

I use Visual Studio 2008. 我使用Visual Studio 2008。

Well you could do it with MSBuild in a post-build event. 那么你可以在一个post-build事件中使用MSBuild做到这一点。

But are you sure you want to do this? 但你确定要这么做吗? It will slow you down, and you probably don't need to publish for every build? 它会降低你的速度,你可能不需要为每个构建发布? Why not just run the site in IIS instead of Cassini. 为什么不在IIS而不是Cassini中运行该站点。

Step 1. Make sure that you have a web project. 步骤1.确保您有一个Web项目。

Step 2. Go to View->Toolbars->Web One Click Publish. 步骤2.转到视图 - >工具栏 - > Web单击发布。

The publish button web button on the toolbar will do what you want... build and publish in one step. 工具栏上的发布按钮Web按钮将按您的要求执行...一步构建和发布。

The easiest way to automate the functionality included in Visual Studio's "publish" action available from the Build menu is to use the web deployment project . 自动化Visual Studio的“发布”操作中包含的功能的最简单方法是使用Web部署项目 There's one for VS2005 as well. VS2005也有一款。 Basically it's an extra project that you add to your solution that will target your web project and when built will publish your web project as part of the build process. 基本上,这是一个额外的项目,您添加到您的解决方案,将针对您的Web项目,并在构建时将作为构建过程的一部分发布您的Web项目。 It makes it dirt simple to automatically build a site as part of build without mucking with MSBuild (though MSBuild isn't that difficult). 它使得自动构建站点作为构建的一部分而不会与MSBuild混淆(虽然MSBuild并不那么困难)。

Here is how I do it in my web site project. 以下是我在网站项目中的操作方法。 Note that this will copy to a folder; 请注意,这将复制到一个文件夹; if you want to publich through FTB, WebDav or SSH, you need to use the Exec task instead of the Copy task and specify a command-line tool that can deploy the files over the desired protocol. 如果要通过FTB,WebDav或SSH公开,则需要使用Exec任务而不是Copy任务,并指定可以通过所需协议部署文件的命令行工具。

Also, you can't edit the AfterBuild task from the project settings in the VS IDE. 此外,您无法从VS IDE中的项目设置编辑AfterBuild任务。 You need to open it in Notepad or your favorite text/XML editor. 您需要在记事本或您喜欢的文本/ XML编辑器中打开它。 (You could even use VS, if you close the solution and enforce it to open the file with the XML editor :-)) (你甚至可以使用VS,如果你关闭解决方案并强制它使用XML编辑器打开文件:-))

There's also a build target that invokes the AspNetCompiler , which I have currently turned off, but you could easily turn on through the MvcBuildViews property value. 还有一个构建目标,它调用我目前已关闭的AspNetCompiler ,但您可以通过MvcBuildViews属性值轻松打开。

  <PropertyGroup>
    <MvcBuildViews>false</MvcBuildViews>
    <DropPath>..\..\drop\</DropPath>
  </PropertyGroup>
  <Target Name="AfterBuildCompiler" Condition="'$(MvcBuildViews)'=='true'">
    <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
  </Target>
  <Target Name="AfterBuild" DependsOnTargets="AfterBuildCompiler">
    <ConvertToAbsolutePath Paths="$(DropPath)">
      <Output TaskParameter="AbsolutePaths" ItemName="FullDropPath" />
    </ConvertToAbsolutePath>
    <Message Importance="High" Text="Binplacing -&gt; @(FullDropPath)" />
    <ItemGroup>
      <Binaries Include="$(OutputPath)**\*.*" />
    </ItemGroup>
    <Copy SkipUnchangedFiles="True" SourceFiles="@(Compile)" DestinationFiles="@(Compile->'$(DropPath)%(Identity)')" />
    <Copy SkipUnchangedFiles="True" SourceFiles="@(Content)" DestinationFiles="@(Content->'$(DropPath)%(Identity)')" />
    <Copy SkipUnchangedFiles="True" SourceFiles="@(EntityDeploy)" DestinationFiles="@(EntityDeploy->'$(DropPath)%(Identity)')" />
    <Copy SkipUnchangedFiles="True" SourceFiles="@(Binaries)" DestinationFiles="@(Binaries->'$(DropPath)%(Identity)')" />
  </Target>

Option 1: Switch from Cruise Control to JetBrains TeamCity (you won't regret it!). 选项1:从Cruise Control切换到JetBrains TeamCity(你不会后悔的!)。 In TeamCity there's an Artifacts option which ... 在TeamCity中有一个Artifacts选项......

"Artifacts are files produced by a build. After finishing a build, TeamCity searches for artifacts in the build's checkout directory according to the specified artifact patterns. Matching files are then uploaded to the server, where they become available for download." “工件是由构建生成的文件。完成构建后,TeamCity根据指定的工件模式在构建的checkout目录中搜索工件。然后将匹配的文件上载到服务器,在那里可以下载。”

Option 2: Create a task in Cruise Control to do an XCOPY after the build is complete. 选项2:在Cruise Control中创建一个任务,在构建完成后执行XCOPY。

<tasks>
    <msbuild>
       ... here's your main build ...
    </msbuild>

  <exec>
    ... define your XCOPY or other executable task here ...
    <buildTimeoutSeconds>900</buildTimeoutSeconds>
  </exec>

Option 3: Create a post-build project in your solution and have a task in it to copy the files over, add a condition on that task that to only trigger when running on cruise control (various environment variables enable this). 选项3:在解决方案中创建一个后期构建项目,并在其中有一个任务来复制文件,在该任务上添加一个仅在巡航控制上运行时触发的条件(各种环境变量启用此功能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM