3 回答

TA貢獻1820條經驗 獲得超3個贊
解釋
解
在項目Y中添加對程序集B的引用。 將虛擬代碼添加到項目X中使用程序集B的文件中。
如果您以后添加了引用項目X的另一個項目,您將不必記住也包括對程序集B的引用(就像您在選項1中所做的那樣)。 您可以有明確的注釋,說明為什么虛擬代碼需要在那里,而不是刪除它。因此,如果有人無意中刪除了代碼(例如,使用一個尋找未使用代碼的重構工具),您可以從源代碼管理中很容易地看到該代碼是必需的,并進行還原。如果使用選項1,而有人使用重構工具來清除未使用的引用,則沒有任何注釋;您只會看到.csproj文件中刪除了引用。
// DO NOT DELETE THIS CODE UNLESS WE NO LONGER REQUIRE ASSEMBLY A!!! private void DummyFunctionToMakeSureReferencesGetCopiedProperly_DO_NOT_DELETE_THIS_CODE() { // Assembly A is used by this file, and that assembly depends on assembly B, // but this project does not have any code that explicitly references assembly B. Therefore, when another project references // this project, this project's assembly and the assembly A get copied to the project's bin directory, but not // assembly B. So in order to get the required assembly B copied over, we add some dummy code here (that never // gets called) that references assembly B; this will flag VS/MSBuild to copy the required assembly B over as well. var dummyType = typeof(B.SomeClass); Console.WriteLine(dummyType.FullName); }

TA貢獻1818條經驗 獲得超8個贊
Content
Always
.
添加回答
舉報