how to use .vsprops file to override VC++ Directories in MS Visual Studio
I'd like to override the directories used by Visual Studio (devenv.exe) for the compiler and library paths. I know how to do this interactively via Tools->Options->VC++ Directories, but I'd like to automate this.
http://msdn.microsoft.com/en-us/library/t9az1d21(VS.80).aspx has a tantalizing note on this: "If you want to set up directory search paths (for your projects) that can be shared by other users or that can be applied across multiple computers, Visual C++ provides an alternative to using this dialog, through project property sheets. For more information, see Property Sheets (C++)."
If you follow the link to Property Sheets documentation, there's a bunch of information on the mechanism but none on the actual properties you need to set.
I found the information populated by the VC++ Directories dialog, in %LocalAppData%\Microsoft\VisualStudio\8.0\VCComponents.dat (for VS 2005, and 9.0 for VS 2008); it seems to set various properties under VC\VC_OBJECTS_PLATFORM_INFO\win32\Directories and ...\x64\Directories.
Has anyone done this before and know what the mapping is from the property names used in VCComponents.dat to the names to use in a .vsprops file?
I'd like this to work in VS2005, VS2008 and VS2010, ideally.
In VS2010, Microsoft has completely done away with the VC++ Directories dialog under View Options, made it per project, and so now you get an interactive UI for editing these directories in Project Properties instead of View Options; this also means that there's a UI for it in the properties manager; then if you want to make changes per-machine instead of per-project like it used to be, you just set a property sheet up the way you want, and make all your projects inherit from it. This sounds like a big improvement over the old way. And a direct way to do what I want to do. But only in VS2010.
VS2005 and VS2008 don't have the UI to do set these properties in a project or property sheet, though; I'm happy to do it by hand but I don't know what it's supposed to look like!
Here's an empty VS 2005 .vsprops file:
<?xml version="1.0"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="pathSettings"
>
</VisualStudioPropertySheet>
I installed VS 2010 and used its neat new GUI to make changes in the search directories; it looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup>
<ExecutablePath>C:\Test;$(PATH)</ExecutablePath>
</PropertyGroup>
</Project>
However, that doesn't work verbatim in VS2005 -- VS2005 refuses to load it (complaining no DTD/schema declaration was found).
I plunked that into the container, in response to which VS2005 tells me "Element 'PropertyGroup' is unexpected according to content model of parent element 'VisualStudioPropertySheet'. Expecting: Tool, UserMacro." Tool 开发者_Python百科and UserMacro are the only things shown in the example in the MSDN page [drat - StackOverflow won't let me as a new user put a hyperlink here -- first Google search result for 'property sheets tool usermacro'] -- maybe those are the only things legal in a VS2005 property sheet?
First of all, there actually is a gui to edit property sheets just the same way as project properties under all VS versions you talk about.
View->Other Windows->Property Manager
brings up a window in which you can see all project configurations and the property sheets hierarchy.
A property sheet can be used to override all properties a vcproj file has, and also has User Macros. To override the paths you talk about, this is en axample property sheet for VS2008 that sets the intermediate, output, include and library directories; put it at the top of the hierarchy in the Propert Manager to make sure it takes effect:
<?xml version="1.0" encoding="Windows-1252"?>
<!-- override paths -->
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="PathSettings"
IntermediateDirectory="$(TEMP)\$(ProjectName)_$(ConfigurationName)"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="d:\api\include"
/>
<Tool
Name="VCLibrarianTool"
OutputFile="c:\mylibs"
/>
<Tool
Name="VCLinkerTool"
OutputFile="c:\myoutput"
AdditionalLibraryDirectories="d:\api\_lib"
/>
This should work for VS2005 as well, but not for VS2010: as you figured out it uses a different format, so you'll have to keep the two of them seperately.
精彩评论