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

查看:568
本文介绍了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.

谢谢您的帮助.

推荐答案

好的,到了5月,我们仍然没有Microsoft的官方解决方案.我使用Powershell和新的.NET核心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
    }
}

删除-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 add/remove命令.可以将其清除为一个交互式脚本.
  • 您还可以进行更改,以使您无需阅读单独的添加/删除脚本,而只需阅读Includes.json并通过解析.sln文件将其与解决方案中当前的项目进行比较.

值得深思.如果您要克隆/下载,请参见以下仓库: 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天全站免登陆