3 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超3個(gè)贊
解釋
解
在項(xiàng)目Y中添加對(duì)程序集B的引用。 將虛擬代碼添加到項(xiàng)目X中使用程序集B的文件中。
如果您以后添加了引用項(xiàng)目X的另一個(gè)項(xiàng)目,您將不必記住也包括對(duì)程序集B的引用(就像您在選項(xiàng)1中所做的那樣)。 您可以有明確的注釋,說明為什么虛擬代碼需要在那里,而不是刪除它。因此,如果有人無意中刪除了代碼(例如,使用一個(gè)尋找未使用代碼的重構(gòu)工具),您可以從源代碼管理中很容易地看到該代碼是必需的,并進(jìn)行還原。如果使用選項(xiàng)1,而有人使用重構(gòu)工具來清除未使用的引用,則沒有任何注釋;您只會(huì)看到.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貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
Content
Always
.
添加回答
舉報(bào)