Zip files after build completes in Visual Studio

前端 未结 3 1526
小鲜肉
小鲜肉 2021-02-02 12:38

I have a requirement where I need to zip some files after I build a solution file.

Could this be achieved automatically once I build my project in Release/Debug mode? <

3条回答
  •  一个人的身影
    2021-02-02 13:37

    Usually I don't put stuff like creating zip files, installers, NuGet packages etc. into my actual project.
    Why? Because when I put it there, it gets executed each time I'm building the project in Visual Studio, for example when I'm debugging.
    But zip files, installers etc. are only needed when I do a release, so I don't want to wait for them to be re-generated each time I press F5 in Visual Studio.

    To make a release, I usually create a batch file that executes a MSBuild project file, which creates everything that's necessary to make a release.
    IMO creating a ZIP file belongs into that MSBuild project file as well.

    You can find all the information you need in these two previous answers by me:

    • How to create a basic batch file and MSBuild project file
      (the actual question there is about building an installer with WiX, but in the beginning I'm creating a MSBuild project file)
    • How to create a ZIP file with MSBuild Community Tasks

    Plus, here's an example MSBuild project file from one of my projects, which does the following:

    • build the project
    • run unit tests
    • create two release folders with binaries (one DLL and one .exe)
    • create two zip files, one for each of the folders with binaries
    • create a NuGet package for the DLL
    • create a ClickOnce setup for the .exe
    • automatically set the correct version number for everything

    The great thing about this approach is that I can make a release, which includes everything I have just listed, with a single click (running a batch file).
    Creating all this stuff takes some time, but as it's not part of the Visual Studio solution, it doesn't run each time I do a build in Visual Studio - I only execute it when I really need it.

提交回复
热议问题