none
How to change project targetframework dynamically RRS feed

  • Question

  • We have to migrate our 500 applications from old framework to 4.5.1 framework. One option is open all application solution and change their entire project Target framework to 4.5.1 one by one. Which is time consuming process and there can be a case where our developer can miss to change target framework. When we open our solution into visual studio 2013 it ask to migrate our projects to VS 2013 compatible. I write utility with following code to do automatically upgrade project or solution file by using following command.

    devenv.exe /upgrade <project file (.vcproj)>
    devenv.exe /upgrade <solution file (.sln)>

    But project target framework is not change, which I can expect it migrate only projects according to VS 2013. Is there any command available where I can pass TargetFramework and along with project file and it migrate it according to that?

    Tuesday, July 14, 2015 4:29 PM

Answers

  • Hello Ankush,

    >> there any command available where I can pass TargetFramework and along with project file and it migrate it according to that?

    Since you are trying to upgrade to 4.5.1, you could use this Target Framework Migrator Visual Studio Extension:

    https://visualstudiogallery.msdn.microsoft.com/47bded90-80d8-42af-bc35-4736fdd8cd13

    It could migrate all your .Net projects to another .Net Framework Version at once. It now also supports to migrate to 4.5.2.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Ankush Bindra Wednesday, July 15, 2015 4:12 AM
    Wednesday, July 15, 2015 1:24 AM
    Moderator

All replies

  • Hello Ankush,

    >> there any command available where I can pass TargetFramework and along with project file and it migrate it according to that?

    Since you are trying to upgrade to 4.5.1, you could use this Target Framework Migrator Visual Studio Extension:

    https://visualstudiogallery.msdn.microsoft.com/47bded90-80d8-42af-bc35-4736fdd8cd13

    It could migrate all your .Net projects to another .Net Framework Version at once. It now also supports to migrate to 4.5.2.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Ankush Bindra Wednesday, July 15, 2015 4:12 AM
    Wednesday, July 15, 2015 1:24 AM
    Moderator
  • Thanks Fred,

    It really help me... :)

    Wednesday, July 15, 2015 4:20 PM
  • You can try the following code. This change a given project in a solution. You can easily modify it to fit your need of multiple solution and multiple project:

            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();



            }

    Wednesday, April 17, 2019 4:32 PM