Editing an MSBuild Project File
It's a small thing, this one - but not a lot of people seem to know about it, so I thought I'd add it in here.
It's not uncommon that I find myself wanting to hack at a .csproj or .vbproj file directly (for example, to set a dependency between a XAML file and its code behind file, or simply to rename the code-behind file). As you probably know, in Visual Studio 2005 we revamped the build system with the introduction of a new technology called MSBuild. Project files are now XML descriptions of the various files, dependencies and property settings that make up an application, along with a means to describe how an individual file type gets built. (More details in this month's MSDN Magazine.)
Unfortunately, you can't just right-click on the project file in Visual Studio and choose "edit", which means that quite a lot of the advanced customization capabilities are opaque from the developer environment. In our customer labs, I therefore frequently see people who have opened Notepad to edit the project file, but of course Notepad is hardly the pinnacle of developer editors.
So here's how to edit a project file within Visual Studio 2005:
- Open the solution that you're working with
- Right-click the specific project that you want to edit
- Choose Unload Project
- Right-click the project again
- Choose Edit <project name>
- Ooh and aah at the MSBuild Intellisense and tooltip help
- Save the project
- Right-click the project file and choose Reload Project
Simple when you know how, isn't it?
Comments
- Anonymous
May 08, 2006
Thanks for that one. Didn't even know it existed (and Alex Kipman didn't tell me either when I beat him up over some MsBuild stuff at TechEd) - Anonymous
June 19, 2006
Hi,
I never knew that we can edit the msbuild like this. usually i'll launch another editor to edit the file.
thanks for the valuable tip. - Anonymous
August 06, 2006
Do I seriously need to manage project guids though? I want to hand edit a project that has project references, is the only way to manage those myself to have to know the project's guid???
Thanks
-bc