Can a Visual C++ Property Sheet refer to a project location?
Is it possible to use a Visual Studio property sheet to specify the directory in which a project file is located?
I have a solution file which contains several projects inside a common directory. If I want to change that directory name for example, I need to change the project path for each project in the solution. If I could use a property sheet to specify the name of that top-level directory, I could just update it if I need to change the directory name.
In a Property Sheet you can define (amongst other things) Include Directories, which will be used by any project in your solution which uses this Property Sheet. This makes it trivial to change an Include Directory across several projects at the same time. You can also add macros which can then be used b开发者_JAVA百科y all the projects.
Essentially, I want to know if there is some way of using Property Sheets (or something else) to add specify some macro to a solution which will allow the path of a project to be a variable.
Imagine the situation, in which I have a project with version v1.0 that is part of several solutions. I want to upgrade to v1.1, so I use a property sheet macro to redefine the Include directory of the header files and output library files.
C:\myproject\somelibrary\v1.0\some_project.proj
C:\myproject\somelibrary\v1.1\some_project.proj
$(LibraryPath) can be changed from v1.0 to v1.1 in my property sheet.
This makes my life easier if I have many solutions which all reference the same Property Sheet. However, in each solution I also need to remove the old v1.0 project files and add the new v1.1 project files.
Is there a way of defining a macro or something similar which will make it possible to change the path of a project for several solutions in one single location? Property Sheets probably won't work since they are added at the project level not the solution level, so I'm looking for something analogous.
You can't do that with a property sheet. The .sln file references the .vcproj (or other project file type) files. And the project files in turn reference the property sheets. So Visual Studio would have to somehow find the property sheets and then go back and load the project files.
An easier solution for what you are trying to do would be to open the .sln in a text editor and use find/replace to change the paths to the project files. You can even use Visual Studio itself for this by using File->Open->File... and then clicking the "Open With..." button instead the normal open button. I'm not sure about Visual Studio 2010, but with 2005 and 2008, you have to click the down arrow on the open button to get to the "Open with..." button. You can then select either the XML editor or the source code editor. When you are done with your changes, save and close the .sln file, then open it the normal way.
What I would do is create a script (could do c++, python is friendlier with os and file-based tasks), to edit the solution file and replace a section of the path.
Could also use an environment variable, to make it easier...
精彩评论