views:

15

answers:

1

I'm trying to add an Import task to a .csproj file programmatically, but I don't want to use the Microsoft.Build.BuildEngine objects to do this because VS will then pop up warnings about the project file being modified from outside of Visual Studio.

I've seen a few pages [1] [2] suggesting that the IVsBuildPropertyStorage interface will let me access the MSBuild parts of the .csproj file, but I'm having trouble figuring out how to do this, or if it's even possible really. It looks like I need to specify the name of the property I want to access, but I'm not sure how to figure that out. Calling GetPropertyValue() for an "Import" property doesn't return anything for project files that are already set up how I want my final results to look:

EnvDTE.Project proj = ...;
var sol = Package.GetGlobalService(typeof(VsSolution)) as IVsSolution;
IVsHierarchy hier;
sol.GetProjectOfUniqueName(p.UniqueName, out hier);
var storage = hier as IVsBuildPropertyStorage;
string val;
storage.GetPropertyValue("Import", String.Empty,
                         (uint)_PersistStorageType.PST_PROJECT_FILE, out val);
// val is null

[1] https://mpfproj.svn.codeplex.com/svn/9.0/Tests/UnitTests/ProjectTest.cs
[2] http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/e1983591-120a-4a2f-a910-e596dd625e68

Thanks. I'd appreciate any suggestions I can get with this.

A: 

Import element is not a Property element in MSBuild nor and Item one.

I think you can't add an Import using IVsBuildPropertyStorage.

madgnome