0

I have a Visual Studio Template Wizard where eventually I need to conditionally (based in user selections) change the .NET target with:

// project is of type EnvDTE.Project

project.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version=v4.5"

The problem is that after this all references to project properties return "Project Unavailable".

After changing the .NET target I need to add some assemblies as references and without the project being available this no longer works.

Inverting the tasks order (first adding the references then changing the target) does not work, because I am adding some dependencies that require .NET 4.5 (and project is originally .NET 4.0).

1 Answer 1

3

Ok, this is how I solved

project.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version=v4.5";

project = (Project)((Array)(Dte.ActiveSolutionProjects)).GetValue(0);

The 2nd line gets a new copy of the Project using a previously initialized instance of Dte (this new project instances mirrors all the changes of the previous instance (even those not saved) so already has the target framework == 4.5 !!).

The new instance can be used to add project references, etc.

1
  • Thanks, this was what I was looking for!
    – Igavshne
    Nov 4, 2017 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.