views:

80

answers:

3

Hi,

For a .NET solution, is there a way to get all the .dll files for each project in the solution? For example, if I make an empty .NET solution (this is Visual Studio 2010 btw), and add 3 projects called "a", "b" and "c", and build each, providing me with dll's a.dll, b.dll, and c.dll, is there any code sample in either C# or Powershell which could give me a collection of of these .dlls (but not any other .dlls like 3rd party libraries used)?

Thanks

A: 

One simple way (without writing a VS addin) would be parsing the project file. The project file (which is in XML format) will have an element called ProjectReference (regular references are in another element, called Reference):

<Project ...>
  <ItemGroup>
    <ProjectReference Include="..\path\YourProject.csproj">
      ...
    </ProjectReference>
  </ItemGroup>
</Project>

You could simply parse this, with any XML API you have in your toolset and get the name of the dll by using the name of the project (the Include attribute). This works of course only if your project has the same name as the dll. If it hasn't, you could open the csproj file and find the element <AssemblyName>

steinar
+2  A: 

It's difficult to implement a 100% robust solution for this scenario. Project files, while usually simple, can get very complex as people take advantage of the flexibility of MSBuild. It's possible for instance for the same project to build assemblies with very different names given specific build settings. This makes it very difficult to pick out the assembly name without understanding the overall build context.

However for the most straight forward cases the following powershell script will do the trick. Make sure that it's run in the same directory as the specified solution file.

gc SomeProject.sln |
    ? { $_ -match "^Project" } |
    % { ($_.Split(","))[1].Trim().Trim('"') } |
    ? { $_ -match ".*proj" } |
    % { $x = [xml](gc $_); $x.Project.PropertyGroup[0].AssemblyName } |
    % { $_ + ".dll" }
JaredPar
Yeah, the two things you need are the `OutputPath` and the `AssemblyName` from each project. But even in the simplest case, the output path changes based on the Configuration and Platform that are selected (eg: Debug vs Release).
Jaykul
A: 

what about using the EnvDTE namespace? A related example is shown here.

bluevoodoo1