开发者

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 mv开发者_运维百科c 2 project is built.

I use Visual Studio 2008.


Well you could do it with MSBuild in a post-build event.

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.


Step 1. Make sure that you have a web project.

Step 2. Go to View->Toolbars->Web One Click Publish.

The publish button web button on the toolbar will do what you want... build and publish in one step.


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. There's one for VS2005 as well. 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. It makes it dirt simple to automatically build a site as part of build without mucking with MSBuild (though MSBuild isn't that difficult).


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.

Also, you can't edit the AfterBuild task from the project settings in the VS IDE. You need to open it in Notepad or your favorite text/XML editor. (You could even use VS, if you close the solution and enforce it to open the file with the XML editor :-))

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.

  <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!). In TeamCity there's an Artifacts option which ...

"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."

Option 2: Create a task in Cruise Control to do an XCOPY after the build is complete.

<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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜