問題描述
支持超過 2 個版本的項目 (Supporting more then 2 versions of a project)
目前我的項目支持2個版本,現在應該支持3個版本。
目前是通過x86
& x64
當我在它們之間切換時,在我的 項目文件 中我有條件加載不同的程序集,例如:
Ver1
<Reference Include="SExtension" Condition="'$(Platform)' == 'x64'">
<HintPath>..\..\_libBinary\ver1\SExtension.dll</HintPath>
</Reference>
Ver2
<Reference Include="SExtension" Condition="'$(Platform)' == 'x86'">
<HintPath>..\..\_libBinary\ver2\SExtension.dll</HintPath>
</Reference>
所以根據平台 x86
OR x64
正在加載不同的程序集。
根據新的需求,我需要添加對第 3 版的支持。(在不久的將來會有另一個)
我正在使用 TeamCity 來創建最終用戶獲得的不同版本的工件。
參考解法
方法 1:
It makes little sense switching between different features based on platform if the features do not really depend on the platform, that's just confusing. Instead just use an arbitrary property with a suitable default and pass it on the commandline. You don't even need conditions here if you set that property to the name of the directory where SExtension needs to be pulled from:
<!‑‑ Put this at the Project Tag level, before the location where it's used ‑‑>
<PropertyGroup>
<!‑‑ Defaults to ver1 if not specified at all ‑‑>
<ExtensionVersion Condition="'$(ExtensionVersion)'==''">ver1</ExtensionVersion>
</PropertyGroup
...
<Reference Include="SExtension">
<HintPath>..\..\_libBinary\$(ExtensionVersion)\SExtension.dll</HintPath>
</Reference>
Modify the property as usual:
msbuild /p:ExtensionVersion=ver3