forked from OData/ODataConnectedService
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
see OData#372
- Loading branch information
Showing
1 changed file
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,46 @@ | ||
using System.CommandLine; | ||
using System; | ||
using System.CommandLine; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Build.Locator; | ||
|
||
namespace Microsoft.OData.Cli | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
{ | ||
Build.Locator.MSBuildLocator.RegisterDefaults(); | ||
RegisterMsBuild(); | ||
GenerateCommand generateCommand = new GenerateCommand(); | ||
RootCommand app = new RootCommand { | ||
generateCommand | ||
}; | ||
await app.InvokeAsync(args); | ||
} | ||
|
||
/// <summary> | ||
/// Tries to register MSBuild from Visual Studio install folder. If not available, register defaults. | ||
/// </summary> | ||
private static void RegisterMsBuild() | ||
{ | ||
const string defaultInstallDirOfVisualStudio = @"C:\Program Files\Microsoft Visual Studio\"; | ||
var installDirOfLatestVisualStudio = Directory.GetDirectories(defaultInstallDirOfVisualStudio, "????", SearchOption.TopDirectoryOnly) | ||
.Where(x => Path.GetFileName(x).All(char.IsDigit)) | ||
.MaxBy(x => Path.GetFileName(x)); | ||
|
||
string pathToMsBuildExeInLatestVisualStudioVersion = Path.Combine( | ||
Directory.GetDirectories(installDirOfLatestVisualStudio, "*", SearchOption.TopDirectoryOnly).FirstOrDefault() ?? string.Empty, | ||
"MSBuild", "Current", "Bin", "MSBuild.exe"); | ||
|
||
if (File.Exists(pathToMsBuildExeInLatestVisualStudioVersion)) | ||
{ | ||
MSBuildLocator.RegisterMSBuildPath(Path.GetDirectoryName(pathToMsBuildExeInLatestVisualStudioVersion)); | ||
} | ||
else | ||
{ | ||
MSBuildLocator.RegisterDefaults(); | ||
} | ||
} | ||
} | ||
} |