0
votes

I have a Silverlight solution that has multiple silverlight projects (Views) that all compile to their own .Xap file.

There is one "master" project that handles the dynamic downloading of the Xap files, which works pretty well.

But now I need to make sure that all the references are set to CopyLocal=false in all the View Projects. Only the "master" project can have CopyLocal=true.

This means that the Xap files generated by the Views stay rather small.

What I would like to do is check post or during the build process to see if any of the View projects have a reference with CopyLocal=true.

What would be a smart way of doing this? Using an external tool in the Post Build event? Or perhaps an addin for Visual Studio ? Or creating a macro in Visual Studio for this?

I have looked at using .extmap with assembly caching, but since you have to specify the assemblies in that, this does not solve my problem. I just need to know if there is a reference with the wrong setting and report that. Fixing it is not the question, that will still be done manually. It's just the notification I need.

Solution has 35 projects now, so dont want to check them all by hand every time.

I found a question similar to this one, but it lists msbuild as a possible solution. I would like to know if there is a way to do this using "code" (be it prebuilt in a tool/addin or otherwise)

2

2 Answers

0
votes

I have chosen to go the Addin path. I created an addin that listens to : BuildEvents.OnBuildBegin

Whenever that event fires I create a list of all projects in the current solution. Doing a bit of recursive searching since there are also Solution folders that make life in DTE world a bit harder.

Then I loop through all the projects and cast them to a VSProject so I can loop through all the references.

Anytime I come accross a reference that is wrong, I create an ErrorTask where I set the Document property to the full solution path of the reference. To do this I Build the path for the project this reference is in, all the way up to the root of the solution.

The ErrorTask is then sent to an ErrorListHelper class I created, that handles the ErrorTasks and also performs navigation.

If I'm done with all the projects and I found any errors, I cancel the current build and show the Error List window, where my ErrorListHelper holds all the Reference Errors I created.

Whenever I want to navigate to the Reference in question, I activate the Solution Explorer window and get the root of it using an UIHierarchy.

Then I walk the path from the root on down, step by step, using the UIHierarchy to get to the UIHierarchyItems and expand them. Until I get to the deepest level (the reference) and I Select that.

Since I only need it for a certain solution and within that solution for certain projects (.Views.* and .ViewModels.*) I also have some checking for those in place during buildup of the Error List.

It works like a charm, already found 12 "wrong" References in 35 projects where I tought all were well.

0
votes

I am using a different path now to do this. I have a base class that I can use to write unit tests that have access to the DTE2 object. This way I dont need an addin. This also works for Silverlight projects since the test class does not actually need access to the Silverlight projects, just being in the solution is enough to be able to iterate through the projects and check the references.