支持超過 2 個版本的項目 (Supporting more then 2 versions of a project)


問題描述

支持超過 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

(by E.Meirstijn)

參考文件

  1. Supporting more then 2 versions of a project (CC BY‑SA 2.5/3.0/4.0)

#visual-studio #assemblies #multiple-versions #msbuild






相關問題

如何在 C# 中使用帶有動態參數的 INSERT INTO SQL 查詢? (How to use a INSERT INTO SQL Query with Dynamic parameters in C#?)

擴展 SSRS 中的圖表功能 (Extending chart functionality in SSRS)

如何將 MVC 5 項目模板添加到 VS 2012? (How can I add the MVC 5 project template to VS 2012?)

Visual Studio - 將按鈕/複選框添加到工具欄以切換只讀文件屬性, (Visual Studio - Add a button/checkbox to a toolbar to switch the readonly file property,)

在 Javascript/Jquery Ajax 調用中使用 WCF 服務 (Consuming WCF service in Javascript/Jquery Ajax call)

Visual Basic 2013 - 控制台輸入令牌? (Visual Basic 2013 - Console Input Tokens?)

您是否知道用於編輯/翻譯資源(.rc)文件的好的程序? (Do you know of a good program for editing/translating resource (.rc) files?)

ADODB.Recordset 數據無法綁定到 datagridview (ADODB.Recordset data cannot bind into datagridview)

Reporting Services - 對數據源視圖 (DSV) 的報表模型 (SDML) 引用 (Reporting Services - Report Model (SDML) reference to Data Source View (DSV))

從 Visual Studio 2005 遷移到 2008 時要注意什麼? (What to look out for when moving from Visual Studio 2005 to 2008?)

動態改變另一個類的標籤值 (Dynamically changing the value of a label from another class)

在同一文件夾中為 .NET 5 和 .NET 6 Preview 3 構建 WebAssembly 項目 (Building WebAssembly project for both .NET 5 and .NET 6 Preview 3 in same folder)







留言討論