7zip Helper Batch File

7zip is an open source archive utility. 7zip has a nice GUI to create basic archive but you need to switch to command line if you want to include/exclude folders. It is boring to type same command repetitively if you have to take zipped backup periodically.

This tiny little batch file (backup.bat) creates password protected 7z archive of the specified folders in the folder where it resides. You don’t type your password in the batch file so you don’t give away the password. You can also specify names of the folder you want to exclude from the archive. As an example, by default, backup.bat archives folders named – Source & doc, and excludes bin,obj, and temp/test folders (see customization section below to know how to change).


Copy backup.bat file in the folder which has the subfolders you want to archive. Navigate to the folder in explorer and open command prompt in the same folder (shift+right click > Open command prompt here…) . Type backup.bat at the command prompt and follow the instructions. Pay attention to instructions which appear on your screen.


7zip (http://www.7-zip.org/)
Powershell (Windows7 up, all versions have powershell by default)
7zip executable path in global path variable
Screenshot (19)


Following is the default 7zip command in the batch file –

7z.exe a -t7z yyyymmddhhmm_filename.7z Docs source -mhe=on -p%password% -xr!bin -xr!obj -x!temp/test

“Docs Source” specify the two folders – docs and source, to archive. You can add/change folders to include here. “-xr!bin -xr!obj -x!temp/test” specify 3 folders to exclude from archive – bin, obj, and temp/test. “r” switch in obj and bin denotes that bin and obj folder could be anywhere in the folder structure.

Visual Studio: Auto-increment Build Number – Part 1/3

Sharp Snippets

There have been two continuous coding focused posts related to DateTime (here and here). I am changing gear in this post to project configuration in Visual Studio.



Some points to note before we start. I will keep this example to VS2010  (but i don’t see any reason why this trick can’t be applied to VS2012 or 2013) . This setup does not involve any add-ins or installations. I will provide complete code which requires to just make a little change in target project setup and the setup will be ready to go. This setup should work whether or not you have any sourcecontrol – GIT, VSS, TFS – connected to your project.

If you are my type you would wish to tag your builds and deliverable incrementally. For large teams and pro grade development environment there are advanced solutions available to automate the process. But what…

View original post 228 more words

Visual Studio: Auto-increment Build Number – Part 3/3

Follow this link for Part 1
Follow this link for part 2

Code Download

Download the zip file with example project and scripts here.

Unzip the package in a temporary folder and read and follow Readme.txt.

First Run

Read the Readme.txt file unzipped from the package downloaded above, and follow all the instruction carefully. Open Visual Studio project properties’ Build Event tab and update the path to PostBuild.Bat, as shown highlighted in the image below. Be cautious to have drive letter included and the full path is enclosed in quotes. Only update path inside the quotes.

Once you F6-build the test project, and if your project builds smoothly you will see Output (show output in Visual Studio from View menu) of the build has messages from auto-increment script. Messages will look something like this:

------ Build started: Project: AutoIncrementBuild, Configuration: Debug x86 ------
AutoIncrementBuild -> J:\Demo\Example\AutoIncrementBuild\bin\Debug\AutoIncrementBuild.exe
------------------------------ Post-build event started -------------------
Updating Build information...
Managing build...
Updating build log...
Log File Location: J:\Demo\Example\AutoIncrementBuild\BuildLog.txt
Dll File: J:\Demo\Example\AutoIncrementBuild\bin\Debug\AutoIncrementBuild.exe
Current Output Dll File Version: 1.7.3669.0
Build log entry for this build - 1.7.3669.0 - 16-10-2013 01:15:11 Debug XXX
Write version 1.7.3670.0 in VersionInfo file.
Written version 1.7.3670.0 in VersionInfo file
Confirmed version 1.7.3670.0 is written in VersionInfo file!
Build log updated successfully.
Build log updated
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Messages above are self explanatory and does the commentary of all major tasks performed by the script. If there is any issue with the script, the error will be listed in output window.

On successful build of the project, BuildLog.txt file in your project directory should have a new entry with an incremented build number.


Let’s have a look at the Post-build event command line:
“J:\Demo\DevTools\AutoBuild\”PostBuild.bat MyParam ManageBLD “$(ProjectDir)” “$(TargetPath)” $(ConfigurationName)
Following are the details about each parameter and what you can do about them:

  • MyParam – In example, this is placeholder parameter. It does not affect auto-increment process, but you can pass some value for this parameter and in PostBuild.bat file, you can have some procedure called on the basis of value in this field. You can leave it as it is
  • ManageBLD – There are two recognizable values for this parameter: ManageBLD and NO_ManageBLD. If this parameter has any value other than ManageBld, Auto-increment will not kick in. You can pass NO_ManageBLD, if you want to skip auto-increment process.
  • $(ProjectDir) – Do not make any changes to this param
  • $(TargetPath) – Do not make any changes to this param
  • $(ConfigurationName) – Sends current configuration value; Debug or Release

You manage Major, Minor, and Revision fields of your project from project properties, Assembly Info section. Auto-increment procedure does not change Major, Minor, or Revision section of the version. It only updates Build part of project version. If you want to reset/renew build number, simply update the build field in File Version section of Assembly Information of project properties. The next auto-increment will take this new number as the base for next increment.

I hope you find this utility useful and productive.

Feedback + Follow = Fuel.

Happy F6-ing.

Visual Studio: Auto-increment Build Number – Part 2/3

Visual Studio: Auto-increment Build Number – Part 2/3

Part 1

Concept || Real

I am using the setup, we are discussing here, for last 8000+ builds I compiled on my dev box with Visual Studio. I can tell you that this is a robust code and pretty smoothly working setup.

What & How?

We will leverage powerful post-build event + PowerShell script (full script is discussed below) to have Visual Studio build process do what we want. We will do following:

  • Write aPowerShell script which does following tasks:
      Pick just-compiled dll from calling project’s folder
      Read File Version field
      Increment Build number field in the version by 1
      Write the new Version number with incremented Build number to AssemblyInfo.cs of the calling project
  • Write a wrapper batch file to call aforesaid PowerShell script
  • Configure project to call the batch file with appropriate params
  • Let Visual Studio know when to run the post-build event

After every build we will have our read-only BuildLog.txt file in project folder updated, like so:


Note: The highlighted header is manually inserted, script does not write the header automatically. If you want header in your BuildLog.txt, edit it manually once and insert header at the top.

So, the conceptual diagram of setup looks like this:


The Script

I wrote this PowerShell script using NotePad++. You will find script very similar to c# because PowerShell utilizes a lot of .NET.  If you wish to edit the script to extend its functionality, you can use any editor of your choice, e.g. PowerShell GUI Editor, which provides excellent debug support.
We will call our PowerShell script file UpdateBuildLog.ps1. Here is the outer structure of our script:


  1. File Header
  2. We will wrap our script in try catch block so as to ensure we know the reason of the script failure in our build output windows. We will see how.
  3. Parameter:projectPath – Path of the project, defaulted to c:\temp\
  4. Parameter:targetDLLFullPath – Where project’s dll is located, defaulted to c:\temp\
  5. Parameter:extraAttribute – Any extra text attribute for build log entry, defaulted to XXX
  6. Parameter:buildConfig – Build configuration, Debug|Release, defaulted to Debug

Let’s have a look at the internals of the script:


  1. Prepare AssemblyInfo.cs path from supplied project location. Write the prepared information to Project’s build output window.
  2. Read just created dll file from the supplied path and file name, and extract version and build number. Write version and build number to build output window. Increment build number by 1 in the extracted version number.
  3. Prepare Build log entry, write the entry into build log text file, make the build log text file readonly again.
  4. Update the AssemblyInfo file with the new version number.
  5. Confirm proper version number is written to AssemblyInfo file and write to build output window.
  6. If there is any issue while updating new version number, write to build output window.

The Batch

We will call our batch file PostBuild.bat.  We will setup our project’s post build event in Visual Studio to call PostBuild.bat with appropriate parameters. Following are important parts of the batch file:


  1. File Header
  2. Prepare parameters received from Visual Studio build events
  3. Call procedures on the basis of supplied switches
  4. Customize the batch file and write your code (by default, this section does nothing)
  5. Customize the batch file and write your code (by default, this section does nothing)
  6. Procedure to call PowerShell script to update build log with incremental build number.

We now have a decent idea of the nuts and bolts, and we  are clear about the structure of the setup, script and the batch file.

Code download and customization in – Part 3

Hope you are still with me.