Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create pre-publish and post-publish scripts in VS2010

I would like to create a script that does some actions, then publish the site to the production, and then runs another script within Visual Studio 2010.

like image 675
Himberjack Avatar asked Nov 21 '10 15:11

Himberjack


2 Answers

Of course it's possible. I thing that you need MSBuild. It already have a lot default tasks like copying, deleting, etc. Also there are a lot third party tasks for MSBuild like SDCTasks or Community Tasks

For example here the one of various ways to deploy web site (using SDCTasks). In this example both web site solution and web services solution will be builded and in case of success they will be published to some remote server and properly configured with release version configuration files.

   <Import Project="$(MSBuildExtensionsPath)\SDCTasks\Microsoft.Sdc.CommonWOBizTalk.tasks"/>
    ...
    <ItemGroup>
        <SolutionToBuild Include="$(BuildProjectFolderPath)/../../website.sln">
            <Targets></Targets>
            <Properties></Properties>
        </SolutionToBuild>

        <SolutionToBuild Include="$(BuildProjectFolderPath)/../../services.sln">
            <Targets></Targets>
            <Properties></Properties>
        </SolutionToBuild>

    </ItemGroup>

  <PropertyGroup>
    <PublishFolder>\\myservername\deployto</PublishFolder>
  </PropertyGroup>

  <Target Name="AfterCompile" DependsOnTargets="PublishWebSite;PublishServices;SetConfiguration"/>

  <Target Name="PublishWebSite">
    <Folder.CleanFolder Path="$(PublishFolder)" Force="True" />
    <Folder.CopyFolder Source="$(OutDir)_PublishedWebsites\MyWebSite" Destination="$(PublishFolder)" />
  </Target> 

  <Target Name="PublishServices">
    <MakeDir Directories="$(PublishFolder)\Services"/>
    <Folder.CopyFolder Source="$(OutDir)_PublishedWebsites\MyService" Destination= "$(PublishFolder)\ Services" />
  </Target>

  <Target Name="SetConfiguration">
      <Copy SourceFiles="$(OutDir)_PublishedWebsites\MyWebSite\WebRelease.config" DestinationFiles="$(PublishFolder)\web.config" />
      <Copy SourceFiles="$(OutDir)_PublishedWebsites\MyService\WebRelease.config" DestinationFiles="$(PublishFolder)\Services\web.config" />
  </Target>
like image 84
Igor V Savchenko Avatar answered Oct 05 '22 12:10

Igor V Savchenko


I think that what your looking for would be a macro that would perform the actions before calling publish, then perform some additional actions. If you're using TFS 2010 as well then you could customize a build definition to do what you're looking for as well.

like image 28
CodeMonkey1313 Avatar answered Oct 05 '22 11:10

CodeMonkey1313