Excluding generated files from source control, include in Visual Studio

Auto generated files you typically don’t want to have under source control. I had this problem when building an Wix installer project, where I gather all files I want to include in my installer via the HeatDirectory task. This generates a file, called for example myfiles.wxs, which I need in my Visual Studio project to compile a valid Microsoft installer. Since the rest of my project depends on this wxs-file I want to include it in my projectfile, but exclude it from source control.

To fix this, I used the following way of working:

  1. Let the file be auto generated
  2. Add the file to the Visual Studio project
  3. Add the file to your source control ignore file
  4. Exclude the file(s) by modifying your project file

Let the file be auto generated

The easy step, let your Visual Studio task or tool generate the file.

Add the file to the Visual Studio project

Add the in previous step generated file to your project.

Add the file to your source control ignore file

Most of the version control systems, have a file where you can specify which files you want to ignore from version control. Add the file, created in step 1 to this ignore file. This prevents we might accidental add this file to source control.

Exclude the file(s) by modifying your project file

We still want the file to be in Visual Studio, but don’t want to see the file actually. So open in a text editor the project file and look for the position where the auto generated file is mentioned. Add the following xml-tags to it:

<Visible>false</Visible>

For a file called AutoGeneratedFile.wxs this will look like this:

<Compile Include="AutoGeneratedFile.wxs">
  <Visible>false</Visible>
</Compile>
Posted in DevOps by Bruno at July 14th, 2017.
Tags:

Leave a Reply