Edit 3:
After more googling it looks like you can't have the TargetFrameworkMoniker property in a .NET 3.5 application. So I guess I should be asking a different question.
How do I change the Target framework from 4.0 to 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?
Original question: I just switched to vs2010. I have an application that uses .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. I'm using EnvDTE.Project to create a project and set the settings. I can't find what setting needs to be set for this.
Edit 1: I'm generating code for about 50 solutions. When I made the switch from vs2005 to vs2010 the projects in those solutions are defaulting to .NET Framework 4.0. So I need to set the .NET Framework to 3.5 when I am generating the code for these solutions.
Edit 2: After a lot of googling I found this. 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.
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.
here is 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
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.
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. 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.
User contributions licensed under CC BY-SA 3.0