public void ChangeFramework()
{
string SolutionFile = @"C:\MyProject\MyProject.sln";
string ProjectName = "MyProject";
System.Type oType = System.Type.GetTypeFromProgID("VisualStudio.DTE", true);
EnvDTE.DTE dte = (EnvDTE.DTE)Activator.CreateInstance(oType, true);
dte.Solution.Open(SolutionFile);
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)
{
EnvDTE.Project oProject = dte.Solution.Projects.Item(i);
oProject.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version = v4.6.2";
}
}
dte.Solution.Close();
}