여러 프로젝트 및 구성에 Visual Studio 프로젝트 속성을 효과적으로 사용
저는 항상 여러 프로젝트가 공통 집합을 사용하도록 속성 시트를 사용하여 프로젝트 구성을 위해 GUI 지원에 내장 된 Visual Studio를 사용해 왔습니다.
이것에 대한 나의 주요 불만 중 하나는 여러 프로젝트, 구성 및 플랫폼을 관리하는 것입니다. 주 GUI로 모든 작업을 수행하면 (프로젝트-> 속성을 마우스 오른쪽 버튼으로 클릭) 빠르게 엉망이되고 유지 관리가 어렵고 버그가 발생하기 쉽습니다 (일부 매크로를 올바르게 정의하지 못하거나 잘못된 런타임 라이브러리를 사용하는 등). 서로 다른 사람들이 서로 다른 위치에 종속성 라이브러리를 배치하고 (예 : 내 모든 라이브러리는 "C : \ Libs \ [C, C ++] \ [lib-name] \"에 있음) 종종 해당 라이브러리의 서로 다른 버전을 관리한다는 사실을 처리합니다. 다르게 (릴리스, 디버그, x86, x64 등) 또한 새로운 시스템에 설정하는 시간을 엄청나게 복잡하게 만들고 버전 제어 및 모든 사람의 경로를 분리하는 데 문제가 있기 때문에 큰 문제입니다. .
속성 시트는 이것을 조금 더 좋게 만들지 만, 하나의 시트가 다른 구성 및 플랫폼에 대해 별도의 설정을 가질 수 없습니다 (드롭 다운 상자가 회색으로 표시됨). 결과적으로 올바른 순서로 상속 된 경우 원하는 작업을 수행하는 많은 시트가 생성됩니다 ( "x86", "x64", "debug", "release", "common", "directories"(BoostX86LibDir과 같은 사용자 매크로를 정의하여 앞서 언급 한 종속성 문제 처리) 및 잘못된 순서로 상속 된 경우 (예 : "x64"및 "debug"앞의 "common")은 잘못된 라이브러리 버전을 연결하거나 출력 이름을 잘못 지정하는 것과 같은 문제를 유발합니다.
내가 원하는 것은 이러한 모든 분산 된 종속성을 처리하고 출력 라이브러리 이름을 "mylib- [vc90, vc100]-[x86]로 지정하는 것과 같이 솔루션의 모든 프로젝트에서 사용되는"규칙 "집합을 설정하는 방법입니다. , x64] [-d] .lib ", 개별 프로젝트, 구성 및 플랫폼 조합에 대해이 모든 작업을 수행 할 필요없이 모두 올바르게 동기화 된 상태로 유지합니다.
나는 필요한 파일을 생성하는 CMake와 같은 완전히 다른 시스템으로 이동하는 것을 알고 있지만 이것은 프로젝트에 새 파일을 추가하는 것과 같은 간단한 작업조차도 다른 곳에서 추가 변경이 필요하므로 다른 곳에서 복잡해집니다. 이러한 종류의 변경 사항을 추적 할 수있는 VS2010 통합이있는 경우가 아니면 둘 중 하나에 완전히 만족합니다.
방금 속성 시트를 훨씬 더 유용하게 만드는 데 도움이되는 가능하지 않은 것 (GUI에 의해 노출되지 않음)을 발견했습니다. 프로젝트 속성 파일에있는 많은 태그의 "Condition"속성은 .props 파일에서도 사용할 수 있습니다!
나는 다음을 테스트로 모아서 훌륭하게 작동했으며 5 (common, x64, x86, debug, release) 별도의 속성 시트 작업을 수행했습니다!
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="UserMacros">
<!--debug suffix-->
<DebugSuffix Condition="'$(Configuration)'=='Debug'">-d</DebugSuffix>
<DebugSuffix Condition="'$(Configuration)'!='Debug'"></DebugSuffix>
<!--platform-->
<ShortPlatform Condition="'$(Platform)' == 'Win32'">x86</ShortPlatform>
<ShortPlatform Condition="'$(Platform)' == 'x64'">x64</ShortPlatform>
<!--toolset-->
<Toolset Condition="'$(PlatformToolset)' == 'v90'">vc90</Toolset>
<Toolset Condition="'$(PlatformToolset)' == 'v100'">vc100</Toolset>
</PropertyGroup>
<!--target-->
<PropertyGroup>
<TargetName>$(ProjectName)-$(Toolset)-$(ShortPlatform)$(DebugSuffix)</TargetName>
</PropertyGroup>
</Project>
유일한 문제는 속성 GUI가이를 처리 할 수 없다는 것입니다. 위의 속성 시트를 사용하는 프로젝트는 대상에 대해 "$ (ProjectName)"과 같은 기본 상속 값만보고합니다.
나는 약간의 개선을했고 누군가에게 유용 할지도 모른다
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="UserMacros">
<!--IsDebug: search for 'Debug' in Configuration-->
<IsDebug>$([System.Convert]::ToString( $([System.Text.RegularExpressions.Regex]::IsMatch($(Configuration), '[Dd]ebug'))))</IsDebug>
<!--ShortPlatform-->
<ShortPlatform Condition="'$(Platform)' == 'Win32'">x86</ShortPlatform>
<ShortPlatform Condition="'$(Platform)' == 'x64'">x64</ShortPlatform>
<!--build parameters-->
<BUILD_DIR>$(registry:HKEY_CURRENT_USER\Software\MyCompany\@BUILD_DIR)</BUILD_DIR>
</PropertyGroup>
<Choose>
<When Condition="$([System.Convert]::ToBoolean($(IsDebug)))">
<!-- debug macroses -->
<PropertyGroup Label="UserMacros">
<MyOutDirBase>Debug</MyOutDirBase>
<DebugSuffix>-d</DebugSuffix>
</PropertyGroup>
</When>
<Otherwise>
<!-- other/release macroses -->
<PropertyGroup Label="UserMacros">
<MyOutDirBase>Release</MyOutDirBase>
<DebugSuffix></DebugSuffix>
</PropertyGroup>
</Otherwise>
</Choose>
<Choose>
<When Condition="Exists($(BUILD_DIR))">
<PropertyGroup Label="UserMacros">
<MyOutDir>$(BUILD_DIR)\Bin\$(MyOutDirBase)_$(ShortPlatform)\</MyOutDir>
<MyIntDir>$(BUILD_DIR)\Build\$(Configuration)_$(ShortPlatform)_$(PlatformToolset)\$(ProjectGuid)\</MyIntDir>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Label="UserMacros">
<MyOutDir>$(SolutionDir)\Bin\$(MyOutDirBase)_$(ShortPlatform)\</MyOutDir>
<MyIntDir>$(SolutionDir)\Build\$(Configuration)_$(ShortPlatform)_$(PlatformToolset)\$(ProjectGuid)\</MyIntDir>
</PropertyGroup>
</Otherwise>
</Choose>
<PropertyGroup>
<OutDir>$(MyOutDir)</OutDir>
<IntDir>$(MyIntDir)</IntDir>
<!-- some common for projects
<CharacterSet>Unicode</CharacterSet>
<LinkIncremental>false</LinkIncremental>
-->
</PropertyGroup>
</Project>
재미있게 보내세요!
이전에 회사 제품 (200 개 이상의 프로젝트)에 대해 동일한 고통을 겪었습니다. 내가 해결 한 방법은 속성 시트의 멋진 계층 구조를 구축하는 것입니다.
The projects inherits the property sheet by its output type, say x64.Debug.Dynamic.Library.vsprops. This vsprops file simply inherits other property sheets using the InheritedPropertySheets attribute
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="x64.Debug.Dynamic.Binary"
InheritedPropertySheets=".\Common.vsprops;.\x64.vsprops;.\Debug.vsprops;.\Runtime.Debug.Dynamic.vsprops;.\Output.x64.Library.vsprops"
>
You can also use variables (i.e. UserMacro, whose value can be absolute or even environment variables) in property sheets to customize a lot of things based on your need. For example, defining a BIN variable in Debug.vsprops
<UserMacro name="BIN" Value="Debug" />
then when you set the output name in the series of vsprops, say, Output.x64.Library.vsprops
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
OutputDirectory="$(BIN)"
>
The $(BIN) variable will be expanded to what's been set (in this case, Debug). Use this technique you can easily construct a nice hierarchy of property sheets to meet your demand.
Now there's one more thing you might want to do: build your own project templates that uses your property sheet set. The real difficult part is to enforce proper usage of the templates and property sheets. My personal experience is that even if everything is setup, somebody will still forget to use the template to create new projects ...
It is possible to create a separate property sheet for each configuration. To do this:
- Create a configuration-specific property sheet
- Open the Property Manager
- Right click the configuration (not the project) that you would like to modify
- Click "Add Existing Property Sheet" and add your sheet
This relieves you from inserting conditions into a single sheet for multiple configurations. If you have some common attributes that you would like to share between configurations, then create a hierarchy. The top sheet can be used in all configurations and the nested sheets will only contain the configuration-specific attribut
As far as the output library goes, you can select all your projects, then bring up the property pages, select All Configurations, All Platforms and then set the Target Name to:
$(ProjectName)-$(PlatformToolset)-$(PlatformShortName)-$(Configuration)
which would give an output like mylib-v100-x86-Debug.lib
We do something similar to this for Additional Library Directories as well, using $(PlatformName) and #(Configuration) to pick out the right library paths, although it does mean some messing around with initial setup of the libraries. eg we have boost install its libs to boost/lib.Win32 or boost/lib.x64.
With regards to libraries, and people installing them in different places, there are a couple of options. If you have a very robust source control system, you can just put everything in source control, living in a libs folder next to your source. That probably won't work if you use more than a few libraries though, or if they are particularly large.
The other option that comes to mind is to set an environment variable on each user machine that points to the root of their libraries folder, eg LIB_ROOT=c:\libraries, and you can then access that in Visual Studio as $(LIB_ROOT).
It sounds like it could be worth checking out a build tool - at my place we use a custom made tool that watches files and projects for changes and figures the dependencies and compile order. Adding a new file is no big deal - compilation is done with msbuild.
If i had to compile more than a bunch of projects I would use something like nant: http://nant.sourceforge.net/
'Program Club' 카테고리의 다른 글
| 앱이 닫히면 Android 서비스가 중지됨 (0) | 2020.11.05 |
|---|---|
| SQL Server와 같은 절에서 조인을 사용하여 select 절에서 Postgresql 하위 쿼리를 수행하는 방법은 무엇입니까? (0) | 2020.11.04 |
| matplotlib에서 줄 바꿈이있는 텍스트 상자? (0) | 2020.11.04 |
| 환경 설정이 변경되었는지 감지하는 방법은 무엇입니까? (0) | 2020.11.04 |
| THREE.js에서 텍스처 사용 (0) | 2020.11.04 |