Ignoring TypeScript-generated JavaScript files in TFS (TFVC) with the ".tfignore" file

Posted: (EET/GMT+2)

 

My trusty combination for web application development is ASP.NET MVC and TypeScript on the client-side. However, if your project is hosted in TFVC (Team Foundation Version Control) in TFS or Azure DevOps (ADO), you will quickly notice that when TypeScript compiler in Visual Studio generates the .js and .js.map files, which are automatically added to TFVC. After the first check-in, the .js files are locked (NTFS "R" attribute) from writing, and so building the project fails.

The TypeScript source files are the ones you want to keep in version control, but the generated .js and .js.map files do not need to be checked in.

When using TFVC, add a .tfignore file to the project root folder. This is usually the same folder where the .csproj file is located.

For example:

MyMvcApplication
    MyMvcApplication.csproj
    .tfignore
    wwwroot
        js
            app.ts
            app.js
            app.js.map

The .tfignore file can contain these rules:

wwwroot\js\*.js
wwwroot\js\*.js.map

This tells TFVC to ignore generated JavaScript and source map files under wwwroot\js. The TypeScript files can still be tracked normally, because they have the .ts file extension.

This keeps source control cleaner and projects buildable. Developers see changes to the real source files, not the generated output.

Remember: if the generated files are already checked in, adding .tfignore is not enough. The ignore file prevents new detected changes, but it does not automatically remove files that are already under version control. In that case, remove the generated files from TFVC first, then check in the .tfignore file.

Note that this top generalizes to other auto-generated/compiler-originated files. Good candidates for this kind of ignore rule are:

  • compiled JavaScript files created from TypeScript (the topic of this post)
  • other temporary build output
  • tool-generated files that can be recreated locally, such as those from T3 templates.

Do not ignore files that are required for deployment unless the build or publish pipeline creates them reliably.

Finally, a tip: keep the ignore rule close to the project it affects. A project-level .tfignore file is easier to understand than a large solution-level ignore file with unrelated rules.