升级多个解决方案的目标框架 [英] Upgrading target framework of multiple solutions

查看:109
本文介绍了升级多个解决方案的目标框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0
下来投票

最爱

有没有办法升级目标框架(例如4.5.2到4.6.1)而无需手动打开每个解决方案并转换目标框架?我遇到了一个扩展的Target Framework Migrator,它可以减轻一些问题的痛苦并升级解决方案中存在的多个项目,但我想升级包含超过250个项目的多个解决方案(大约100个),因此试图找到一种自动化方法这个活动。



我尝试了什么:



我试过找到一种自动化Target Framework Migrator的方法,但由于它是一个visual studio扩展,我无法使它在VS环境之外运行。

我也尝试从powershell更新cprojs但是它不仅是csproj在框架迁移中发生变化,还有其他文件(如web.config,表格应用程序中的设置文件等)

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)

推荐答案

你可以可能会编写一个实用程序,在特定文件夹中查找 csproj config 文件。这应该寻找 TargetFrameworkVersion 汇编 httpRuntime 和<这些文件中的code> supportedRuntime 标签并根据需要进行更新。
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.


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



}


这篇关于升级多个解决方案的目标框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆