1

We have many solutions containing hundreds of projects. During migration to new version of VisualStudio we have to change target framework version for all projects. But it is very ineffective to change this setting by clicking project by project Properties/Application/TargetFramework.

Can we change version of all projects in a solution at once? Is there some way to do this activity automatically/programatically?

rahulga
  • 23
  • 2

1 Answers1

2

csproj files are nothing but XML, editing the programmatically is easy enough.

Here's a little app I have created that utilises Linq-Xml to find and update all csproj files under a root folder:

var path = @"--Path to Root--";
var files = Directory.GetFiles(path, "*.csproj", SearchOption.AllDirectories);

XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";

foreach (var file in files)
{
    var doc = XDocument.Load(file);
    var element = doc.Descendants(ns + "TargetFrameworkVersion").Single();
    element.Value = "v4.5";
    doc.Save(file);
}

As you have tagged this as , you may need to perform a checkout on all the csproj files, to remove the read-only flag. Or, alternatively, just check out everything and then use tfpt uu to revert the unchanged files.

Community
  • 1
  • 1
DaveShaw
  • 52,123
  • 16
  • 112
  • 141