Search code examples
visual-studio-2008projects-and-solutionsassembly-attributes

Changing a project's files based on solution in Visual Studio 2008


In one C# solution I have several projects that share a CommonAssemblyInfo.cs file, so that certain assembly attributes are shared across all projects. This works fine so long as I only have one CommonAssemblyInfo.cs file. However I have several solutions (applications) which use these projects, and each solution has its own version of CommonAssemblyInfo.cs.

How can I make the projects use a different CommonAssemblyInfo.cs file depending on which solution they are in?

In the end I want my assemblies to have attributes specific to the solution they were compiled from.

I don't think I can make them files Solution files because they can't all be in the same directory with the same filename. I can't use pre-build events because I don't have a particular project which is always built first. I would prefer not to use a build script because I would like to be able to build and run the solutions through the Visual Studio environment.


Solution

  • No, I don't believe you can't do this - and to me, it sounds like a really bad idea in the first place. If two binaries are built from exactly the same source, with exactly the same configuration, why would it make sense for them to have different attributes?

    What are you trying to achieve with this? IMO you should have a really good reason before you make a build more complicated and go against the normal way of doing things.

    I'd also suggest that you only specify genuinely common things in the CommonAssemblyInfo.cs file - things like the company name. Then each project can have its own AssemblyInfo.cs with project-specific settings, as normal. I'm personally not a big fan of sharing any source files between projects, but I can see how it makes a certain amount of sense in this case.