Include the date in the file name of the web publication publication; visual studio

When creating a new deployment package (for example, behind http://msdn.microsoft.com/en-us/library/dd465323(v=vs.110).aspx ) you are prompted for the location of the package.

I would like to add a timestamp to this filename so that I can easily access older versions just by looking at the output location.

i.e. I would like to provide a value like this: Packages \ Test \ MyProject {yyyy-mm-dd hh.mm.ss}

.zip ... where the values ​​in curly braces are replaced with the current date / time.

Is this possible through your own visual studio? If so, how can this be done?

+3


source to share


1 answer


you can do this by editing the csproj file as follows (you have to open it as a text file): - At the end of the file you will find a comment with AfterBuild and BeforeBuild targets, 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 line and the following commands:

    cd path_to_your_project
    
    msbuild /t:PublishMyProject
    
          

You can create a bat file to execute these commands.

+4


source