Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
0 down vote
favorite
Is there any way to upgrade target framework (e.g. 4.5.2 to 4.6.1) without manually opening each solution and converting the target framework? I have come across an extension Target Framework Migrator which eases the pain a bit and upgrades multiple projects present in a solution but I want to upgrade multiple solutions (around 100) which contains more than 250 projects, thus was trying to find a way to automate this activity.

What I have tried:

I have tried to find a way to automate Target Framework Migrator but since it is a visual studio extension I couldn't succeed to make it run outside of the VS environment.
I have also tried to update cprojs from powershell but it is not only csproj which changes in framework migration, there are other files too (like web.config, settings file in case of form applications etc)
Posted
Updated 17-Apr-19 6:28am
Comments
Suvendu Shekhar Giri 26-Feb-16 1:02am    
100 solutions at a time? really?
Are you a hosting provider?
Indranil Pal 26-Feb-16 1:06am    
It's a large enterprise application with lot of components. Any help is appreciated

You can probably write a utility which looks for csproj and config files in a specific folder. This should look for TargetFrameworkVersion, compilation, httpRuntime and supportedRuntime tags in these files and update them as needed.
 
Share this answer
 
Comments
Indranil Pal 26-Feb-16 1:58am    
Thanks for your suggestion d@nish, but in form applications the property files are changed (Resource.Designers.cs and Settings.Designer.cs). Try to create a sample form application in 4.5.2 ,change it to 4.6.1 and then compare the changes, you will know what I am talking about.
dan!sh 26-Feb-16 2:25am    
So, just add that to list. You can make use of MSBuild to compile all the solutions.
koolprasad2003 26-Feb-16 2:20am    
As Danish suggest you can write a code to change csproj and config files and change given parameters but for converting DLL's you need to recompile them again
Indranil Pal 26-Feb-16 2:23am    
Thanks @Koolprasad for your suggestion, I too thought of that, but there are more changes in Form application (check my comment above)
public void ChangeFramework()
{
    //Add Reference to envdte (Assemblies\Extensions\envDTE)


    string SolutionFile = @"C:\MyProject\MyProject.sln";
    string ProjectName = "MyProject";


    //------------------------------------------------------------------------
    //Find the Program ID from the registry for VisualStudio.DTE
    //Look it up In Registry: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes

    System.Type oType = System.Type.GetTypeFromProgID("VisualStudio.DTE", true);
    EnvDTE.DTE dte = (EnvDTE.DTE)Activator.CreateInstance(oType, true);


    //------------------------------------------------------------------------
    //Open your Solution
    dte.Solution.Open(SolutionFile);



    //------------------------------------------------------------------------
    //Now In your solution go through what is listed in dte.Solution.Projects and find the one that match what you want to change target for

    int iItemsCount = dte.Solution.Projects.Count;
    string sCurrent = "";

    for (int i = 1; i <= iItemsCount; i++)
    {

        sCurrent = dte.Solution.Projects.Item(i).Name;

        if (dte.Solution.Projects.Item(i).Name == ProjectName)
        {
            //Once you find your project, Change the Framework
            EnvDTE.Project oProject = dte.Solution.Projects.Item(i);
            oProject.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version = v4.6.2";
        }
    }


    //------------------------------------------------------------------------

    //Close your Solution
    dte.Solution.Close();



}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900