Monday, January 16, 2006

(Visual Studio) Linked files gotchas, why do I get the same error/warning twice (more than once)

when you link to another file in the same solution (different project) you end up with a file in one project and the same file (virtually) in another project and so when you build the solution, which is what one usually does, you get duplicated errors (same error, same file, same line number) because all of the projects get compiled and if there is an error in the file that is linked, you get
- one error for the project the file belongs to,
- and another error (duplicated) for the project where the file is linked

there are different workarounds, most important is the fact that you should simply be aware of this behaviour, to avoid this there are different workarounds
- only build the solution if you have to, remember that the solution builds all of the projects in it, so if you are working in one of the projects of the solution, instead of building the solution, build only the project you are working on, to do this:

- from solution explorer, click on the project you want to build
- from the Build menu click "Build [your project here]"

an easier way to do this is to customize your tool bar, to do this
- right click anywhere in your tool bar (where all the little buttons are)
- click customize
- click on the commands tab
- select the "Build" category
- find the "Build Selection" option, drag that over to your toolbar, and drop it where you want it

you can even go further and assign a shortcut to it
- while having the "Build Selection" option highlighted click the "Keyboard" button (at the bottom)
- in the "show commands containing" box, type "Build" (without the quotes)
- highlight the Build.BuildSelection
- go to the Press shortcut key and press the key combination that you want to use for that, if there are any conflicts it will tell you where that key combination is being used in the "shortcut currently used by", in most cases you should use one that is rarely or not used, once you have the key combination, click assign, it might ask you to save a copy of your current default settings, you can just assign the name of the backup copy and click yes

now you can use that combination to quickly build only the project you are working with and not have all those duplicated errors

No comments: