[英]How can I progrommatically change the target framework from 4.0 to 3.5 of a project/solution?
Edit 3: After more googling it looks like you can't have the TargetFrameworkMoniker property in a .NET 3.5 application. 编辑3:经过更多的谷歌搜索后,.NET 3.5应用程序中似乎无法拥有TargetFrameworkMoniker属性。 So I guess I should be asking a different question.
所以我想我应该问一个不同的问题。
How do I change the Target framework from 4.0 to 3.5? 如何将目标框架从4.0更改为3.5? Unfortunately, I can only find stuff on how to go the other way.
不幸的是,我只能找到其他方法的东西。 or better yet how do i progrommatically set the target framework version of a project to something other than 4.0?
还是更好,但是我如何以编程方式将项目的目标框架版本设置为4.0以外的版本?
Original question: I just switched to vs2010. 原始问题:我刚刚切换到vs2010。 I have an application that uses .net 3.5.
我有一个使用.net 3.5的应用程序。 It loads plugins which are generated by a different app.
它加载由其他应用程序生成的插件。 The plugins are using .net 4 and there for cannot be loaded.
插件使用的是.net 4,因此无法加载。 I'm using EnvDTE.Project to create a project and set the settings.
我正在使用EnvDTE.Project创建一个项目并设置设置。 I can't find what setting needs to be set for this.
我找不到为此需要设置的设置。
Edit 1: I'm generating code for about 50 solutions. 编辑1:我正在为大约50个解决方案生成代码。 When I made the switch from vs2005 to vs2010 the projects in those solutions are defaulting to .NET Framework 4.0.
当我从vs2005切换到vs2010时,这些解决方案中的项目默认为.NET Framework 4.0。 So I need to set the .NET Framework to 3.5 when I am generating the code for these solutions.
因此,当我为这些解决方案生成代码时,需要将.NET Framework设置为3.5。
Edit 2: After a lot of googling I found this . 编辑2:经过大量的搜寻后,我发现了这个 。 so then I tried this:
所以我尝试了这个:
loProp = vsGetProperty("TargetFrameworkMoniker");
vsSetValue(loProp, ".NETFramework,Version=v3.5");
the definitions for those two methods are below. 这两种方法的定义如下。 as far as I can tell they do the same this as
据我所知,他们所做的与
project.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version=v4.0,Profile=Client";
I start getting an Property Unavailable Exception later in the code. 我稍后会在代码中开始获取“属性不可用异常”。 When I remove the new lines everything works except the projects target framework is still 4.0.
当我删除新行时,除项目目标框架仍为4.0之外,其他所有项目均正常工作。
The code generators target framework is 3.5 so I can't use the FrameworkName class like shown in the second example in that link. 代码生成器的目标框架为3.5,因此我无法使用该链接中第二个示例所示的FrameworkName类。
here is vsGetProperty 这是vsGetProperty
protected Property vsGetProperty(string aProperty)
{
bool lbDone = false;
int liCount = 0;
Property loProp;
while (!lbDone && liCount < pMaxRetries)
{
try
{
loProp = pProject.Properties.Item(aProperty);
lbDone = true;
return loProp;
}
catch (System.Runtime.InteropServices.COMException loE)
{
liCount++;
if ((uint)loE.ErrorCode == 0x80010001)
{
// RPC_E_CALL_REJECTED - sleep half sec then try again
System.Threading.Thread.Sleep(pDelayBetweenRetry);
}
}
}
return null;
}
and vsSetValue 和vsSetValue
protected void vsSetValue(Property aProperty, string aValue)
{
bool lbDone = false;
int liCount = 0;
while (!lbDone && liCount < pMaxRetries)
{
try
{
aProperty.Value = aValue;
lbDone = true;
}
catch (System.Runtime.InteropServices.COMException loE)
{
liCount++;
if ((uint)loE.ErrorCode == 0x80010001)
{
// RPC_E_CALL_REJECTED - sleep half sec then try again
System.Threading.Thread.Sleep(pDelayBetweenRetry);
}
}
}
}
I think you may be putting a bit too much effort and thought into your problem/solution. 我认为您可能会为您的问题/解决方案投入过多的精力和思想。 Maybe it's different because how much code you have in your projects.
也许有所不同,因为您的项目中有多少代码。 As long as they're not using 4.0 features, I don't see why you couldn't open the project properties (right click the project name in solution explorer, select properties) and change the target framework in the application tab.
只要他们不使用4.0功能,我就看不到为什么您无法打开项目属性(在解决方案资源管理器中右键单击项目名称,选择属性)并在应用程序选项卡中更改目标框架。
It should present warning when switching. 切换时应显示警告。 That's what has happened to me when I've changed from 4.0 client profile to 4.0.
当我从4.0客户端配置文件更改为4.0时,这就是我发生的事情。 I would make sure you have all your code checked in and then try this method.
我将确保您已签入所有代码,然后尝试使用此方法。 If it fails and/or breaks, don't commit the conversion and replace with the latest.
如果失败和/或中断,请不要提交转换并替换为最新的转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.