Search code examples
deploymentvisual-studio-2013timestampweb-deploymentweb-deployment-project

Include date in web publishing package filename; visual studio


When creating a new deployment package (e.g. per http://msdn.microsoft.com/en-us/library/dd465323(v=vs.110).aspx) you're asked to provide a package location.

I'd like to append a timestamp to this filename, so that I can easily access older versions, just by browsing the output location.

i.e. I'd like to specify a value such as this: Packages\Test\MyProject{yyyy-mm-dd hh.mm.ss}.zip ...where the values in the braces are replaced by the current date/time.

Is this possible through native visual studio? If so, how can it be done?


Solution

  • you can do that by editing your csproj file as follows (you have to open it as a text file): - Near the end of the file you will find a comment with the targets AfterBuild and BeforeBuild, right after this comment add the following code

    <Target Name="OnBeforePublishMyProject">
        <PropertyGroup>
          <_PackageTempDir>H:\Cs\Test\build.$([System.DateTime]::Now.ToString("yyyy.MM.dd.HH.mm.ss"))</_PackageTempDir>
          <AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>
        </PropertyGroup>
      </Target>
      <Target Name="PublishMyProject" DependsOnTargets="Build;OnBeforePublishMyProject;PipelinePreDeployCopyAllFilesToOneFolder">
      </Target>
    
    • Now you can Publish your project using the Visual Studio Command prompt and the following commands:

      cd path_to_your_project
      
      msbuild /t:PublishMyProject
      

    You can create a bat file to execute those commands too