3

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?

JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
  • Is that really necessary? The metadata for the file will include the date and time. – Ramsay Smith Nov 05 '14 at 19:18
  • Thanks for the tip @RamsaySmith; however if newly created files have the same name the original would be overwritten. If there's some way to avoid that (e.g. generate a new guid, or add a version number to the filename) that would be better; but I don't know if that's possible either. A script could be used to add a timestamp or copy/move the file - but it would be better if there was a way to do this directly from VS. – JohnLBevan Nov 05 '14 at 19:23
  • 1
    You can do that using a MSBuild script. I will provide more details in a moment, too bad the bouty will be expired by then :( – alessandroasm Nov 06 '14 at 20:23

1 Answers1

7

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

alessandroasm
  • 272
  • 1
  • 2
  • 8