views:

620

answers:

3

This is the question that has been posted to MSDN forums some time ago, and stayed unanswered to this day:

http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/676b13d4-acfc-4252-b102-5fc0553e4b81/

The property I'm interested in is ProjOutputReferences, stored in the Visual Studio solution (.sln) file.

In Visual Studio, this property is accessible through Property Pages dialog of a Silverlight WebSite project (requires that you have Silverlight Tools for VS2008 installed). There, there is a page called "Silverlight Applications" on which the content of the above mentioned property can be edited.

I need to access it programmatically inside my add-in, through VS automation or low-level interface(s).

+1  A: 

Hi “prog2008”,

In the latest released version of the Silverlight Tools for VS 2008 SP1, the list is persisted in the SilverlightApplicationList property in the referring project file. For example, I have SilverlightApplication2 and SilverlightApplication2.Web in my solution (the latter references the former). I have the following node in my SilverlightApplication2.Web.csproj file:

<SilverlightApplicationList>{BBA7B148-42AE-477E-BB5E-0BA5AEC0A467}|..\SilverlightApplication2\SilverlightApplication2.csproj|ClientBin|False</SilverlightApplicationList>

There really isn’t a way to access this property via purely DTE, but you can use the Visual Studio SDK / VSIP interfaces to do so (specifically, you want to get the IVsBuildPropertyStorage interface for access to MSBuild properties). Here is a code snippet (runs in a menu command handler in a VSPackage):

IVsSolution solution = GetService(typeof(SVsSolution)) as IVsSolution;

IVsHierarchy hierarchy;
solution.GetProjectOfUniqueName(@"SilverlightApplication2.Web\SilverlightApplication2.Web.csproj", out hierarchy);

IVsBuildPropertyStorage buildPropertyStorage = hierarchy as IVsBuildPropertyStorage;

if (buildPropertyStorage != null)
{
    string silverlightAppListValue;
    buildPropertyStorage.GetPropertyValue("SilverlightApplicationList", "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out silverlightAppListValue);

    MessageBox.Show(silverlightAppListValue);
}

If you still want to try doing this from an Addin, you’ll have to get follow the approach that Craig mentions to cast the DTE object to an IServiceProvider (so you can call GetService).

-Aaron Marten

Aaron Marten
A: 

Thanks Aaron,

Your code snippet indeed addresses the case when there is a WebApplication project within a solution.

In my scenario, there is a Web Site (and not a web application project) within a solution. I guess that's why those Silverlight-related settings end up being written in a .sln file (there's no project file).

IVsBuildPropertyStorage apparently serves only to read project files and .user files. Would it be possible to read the .sln in some similar way, so that I can access those settings I'm after?

Thanks for your (additional) help!

(I'll mark your reply as the answer)

A: 

Since .sln files are just text files, try editing your .sln file using Notepad. You should be able to find the property you are looking for listed there. Assuming the information is in an understandable format, you should then be able to use a simple text parser to extract the info from the .sln programmatically.

muusbolla