VS 2017 通过文件路径引用本地项目(如在 VS 2015 中使用 global.json) [英] VS 2017 reference local projects by filepath (like using global.json in VS 2015)

查看:56
本文介绍了VS 2017 通过文件路径引用本地项目(如在 VS 2015 中使用 global.json)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VS 2015 中,我们曾经能够像这样在 global.json 中指定本地路径:

In VS 2015, we used to be able to specify a local path in global.json like so:

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

然后它将该路径中的所有项目添加到当前解决方案中,使我们能够轻松地从现有项目中引用它们.

It would then add all the projects from that path to the current solution, allowing us to easily reference them from existing projects.

现在 VS 2017 已将其模型更改为使用 csproj,并在此过程中摆脱了 project.json 和 global.json,有人知道这样做的方法吗?

Now that VS 2017 has changed its' model to using csproj, and getting rid of project.json and global.json in the process, does anybody know of a way to this?

我得到的最好的结果是手动将其他项目一个一个地包含到解决方案中.然后,在所有需要引用它的现有项目中,我将不得不编辑他们的 csproj 以包含它们.与以前在一个位置简单地包含文件路径的方式相比,这确实很麻烦.

The best I've gotten is to manually include the other projects, one by one, into the solution. Then, in all the existing projects that need to reference it, I would have to edit their csproj to include them. This is really cumbersome compared to the previous way of simply including a filepath in one location.

感谢您对此的任何帮助.

Thanks for any help with this.

推荐答案

好吧,伙计们,现在是 5 月,我们仍然没有来自 Microsoft 的官方解决方案.我使用 Powershell 和新的 .NET core CLI 得到了一些工作.dotnet.exe 中已经内置了用于从项目中添加/删除解决方案的命令,所以这就是我想出的.

Alright guys, it's May and we still don't have an official solution from Microsoft. I got something working using Powershell and the new .NET core CLI. There's already commands built into dotnet.exe to add/remove solutions from a project, so here's what I came up with.

Includes.json

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

Add-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
    }
}

Remove-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 中轻松修改它.

It's a couple extra steps compared to using the old Global.json file, but it does what we need. To make it really convenient, add a solution folder and include the Includes.json so you can easily modify it from within Visual Studio.

一些注意事项:

  • 添加/删除脚本几乎完全相同,唯一的区别是 dotnet sln 添加/删除命令.这可能可以清理成一个交互式脚本.
  • 您还可以进行更改,以便无需单独的添加/删除脚本,只需阅读 Includes.json 并通过解析 .sln 文件将其与解决方案中当前的项目进行比较.

只是思考的食物.如果你想克隆/下载,这里是 repo:https://github.com/rushfive/VS2017-Includes

Just food for thought. Here's the repo if you want to clone/download: https://github.com/rushfive/VS2017-Includes

这篇关于VS 2017 通过文件路径引用本地项目(如在 VS 2015 中使用 global.json)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆