25

I want to be able to automatically publish to a local folder each time a web asp.net mvc 2 project is built.

I use Visual Studio 2008.

Rohit
  • 3,610
  • 7
  • 45
  • 76
  • I agree with @Luhmann -- why would you want to do this? – PatrickSteele Feb 14 '10 at 21:36
  • Also agree with @Luhmann. :) Not only that, but you'll probably be publishing in debug mode, which wouldn't be good to test/release against. – Dan Atkinson Feb 14 '10 at 22:46
  • 2
    This could be for a build server where Visual Studio is used to compile. While non-ideal, it would make sense until their builds are automated. – Jaxidian Apr 07 '10 at 19:06
  • yes, we have found that using msbuild for build server builds does not work for few addons. – Rohit Apr 08 '10 at 11:13
  • Our builds are automated using ccnet – Rohit Apr 08 '10 at 11:13
  • 2
    It is usefull : apart the optimization and automation, precompiling a web app (on a local machine or integration server like ccnet in this case) ensure that the uncompiled webapp resources (like aspx, resources...) are valid and well suited for a deployment. – JoeBilly Apr 08 '10 at 22:23
  • Just the way `Rebuild` means `Clean + Build`, I wish we had an option named `Deploy` which meant `Build + Publish on successful built`. – Saeed Neamati Jun 12 '12 at 07:00
  • You would want to do this when you have wix setup project (For MVC Project) in your solution, which uses directory harvest. now normal build in visual studio will only give you binaries but you want to have published output for harvesting. if you are building wix setup project on dev machine in the solution then what would you do if the published output from a mvc project is not there. – Gurpreet Apr 07 '15 at 19:57

5 Answers5

14

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.

Luhmann
  • 3,860
  • 26
  • 33
7

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.

Daeron
  • 79
  • 1
  • 1
  • Excellent! I've been wanting to know how to do this for a while! This saves about a hundred clicks a week!! :) – Ayo I Mar 17 '14 at 01:35
5

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

Peter Oehlert
  • 16,368
  • 6
  • 44
  • 48
2

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>
Franci Penov
  • 74,861
  • 18
  • 132
  • 169
  • 1
    BTW you can easily edit the project XML in Visual Studio if you just right click the project, Unload it, then right click Edit on it. Reload it when done. – Ian Mercer Apr 09 '10 at 05:44
0

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

Ian Mercer
  • 38,490
  • 8
  • 97
  • 133