2017-03-10 36 views
5

在2015年VS,我們以前可以在global.json指定本地路徑,像這樣:VS參考2017年地方項目由文件路徑(如在2015年VS使用global.json)

{ 
    「projects」: [ 「src」, 「test」, 「C:\\path\\to\\other\\projects」 ] 
} 

這將然後將該路徑中的所有項目添加到當前解決方案中,以便我們輕鬆地從現有項目中引用它們。

既然VS 2017已將其模型更改爲使用csproj,並且在此過程中刪除了project.json和global.json,是否有人知道這種方法?

我得到的最好的結果是手動將其他項目一個接一個地包含到解決方案中。然後,在所有需要引用它的現有項目中,我將不得不編輯它們的csproj以包含它們。與以前只在一個位置包含文件路徑的方式相比,這非常麻煩。

感謝您的任何幫助。

+0

可能重複[.net核心(csproj)global.json'項目'等效](http://stackoverflow.com/questions/42773815/net-core-的csproj-全球JSON-項目等效) – Set

回答

0

好的傢伙,這是五月,我們還沒有從微軟的正式解決方案。我有一些使用Powershell和新的.NET核心CLI的工作。 dotnet.exe中已經有了一些命令來添加/刪除項目中的解決方案,所以這就是我想出的。

Includes.json

{ 
    "Includes": [ 
     "C:\\projects\\SomeProjectA\\src", 
     "C:\\git\\SomeProjectB\\src" 
    ] 
} 

附加Includes.ps1

echo "Beginning import of projects in Includes.json" 

$JsonIncludes = (Get-Content -Raw -Path "Includes.json") | ConvertFrom-Json 

$IncludePaths = $JsonIncludes.Includes; 
foreach ($IncludePath in $IncludePaths) { 

    $ProjectFiles = Get-ChildItem ($IncludePath + "\*") ` 
        -Include *.csproj ` 
        -Recurse ` 
        | % {$_.FullName } 

    foreach ($ProjectFile in $ProjectFiles) { 
     dotnet sln add $ProjectFile 
    } 
} 

刪除,Includes.ps1

echo "Beginning removal of projects in Includes.json" 

$JsonIncludes = (Get-Content -Raw -Path "Includes.json") | ConvertFrom-Json 

$IncludePaths = $JsonIncludes.Includes; 
foreach ($IncludePath in $IncludePaths) { 

    $ProjectFiles = Get-ChildItem ($IncludePath + "\*") ` 
        -Include *.csproj ` 
        -Recurse ` 
        | % {$_.FullName } 

    foreach ($ProjectFile in $ProjectFiles) { 
     dotnet sln remove $ProjectFile 
    } 
} 

與使用舊的Global.json文件相比,這是一些額外的步驟,但它確實符合我們的需求。爲了使其非常方便,請添加一個解決方案文件夾幷包含Includes.json,以便您可以在Visual Studio中輕鬆修改它。

一些注意事項:

  • 添加/刪除腳本幾乎完全一樣,唯一的區別是DOTNET SLN添加/刪除命令。這可能可以清理成一個交互式腳本。
  • 您還可以更改內容,以便不必單獨添加/刪除腳本,只需閱讀Includes.json,然後通過解析.sln文件將其與目前解決方案中的項目進行比較。

只是想一想。這是回購,如果你想克隆/下載:https://github.com/rushfive/VS2017-Includes