Andrej Tozon's ***OLD*** blog

In the Attic

Google
Web andrej.blogspot.com   

8/16/2004

VS.NET: File-copying projects and referencing all of them from the same project

I've been asked this question a few times in a last couple of months.

Sometimes you want to shorten the time needed to start up a new project for your component by simply copying the files of an existing, possibly similar project you worked on before. While this solution will generally work, you will encounter some problems when referencing both components (the original and the copy) from the same project in the solution. Sure, you've changed the name of the copied project, all of the files, possibly even the namespace your component resides in. But when you try to add a reference to the new component from the main project, already referencing the original component, nothing happens. There's no warning, message box or anything, and your new component just won't show in the references list.

You check the new project's properties, change the assembly name if you haven't done that already [funny thing - if two or more projects in your solution have the same assembly name assigned to them, the solution will compile without any warning, but you will be stuck with only one executable/dll - the one which compiled last].
Now, all project properties seem alright, but VS still refuses to add the new reference. It's because when you copied the project, you also copied its GUID, an unique identifier, by which, evidently, VS keeps track of the projects.

So, in order to get this thing done, you have to create a new GUID and assign it to the new component project. I haven't found any easier solution, so this is what I would do:

1. Generate new GUID: from the VS Tools menu, select item Create GUID - this will bring up a new window, which will help you create a new GUID for your project. In the GUID Format section select the option 4. Registry format. The resulting GUID will be shown in the result section of the window. You can generate new GUID by hitting the New GUID button. When you're fine with the generated number, click the Copy button, which will copy the number to the clipboard.

2. Paste the GUID in the project file: in your favorite text/XML editor, open the .csproj file, which resides in your new project's folder. Find the text ProjectGuid = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" and replace existing GUID with new by pasting it from the clipboard.

3. Save the file and reopen the solution in VS.

I haven't found any better way to do this but it gives me an idea for a VS plug-in...