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.
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?
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.
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
}
}
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.
Some notes:
Just food for thought. Here's the repo if you want to clone/download: https://github.com/rushfive/VS2017-Includes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With