-
Notifications
You must be signed in to change notification settings - Fork 172
/
DotNetHelper.cs
61 lines (47 loc) · 2.62 KB
/
DotNetHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Tools.Utilities;
using Xunit.Abstractions;
#nullable enable
namespace Microsoft.CodeAnalysis.Tools.Tests.Utilities
{
internal static partial class DotNetHelper
{
public static async Task<int> NewProjectAsync(string templateName, string outputPath, string languageName, ITestOutputHelper output)
{
var language = languageName switch
{
LanguageNames.CSharp => "C#",
LanguageNames.VisualBasic => "VB",
LanguageNames.FSharp => "F#",
_ => throw new ArgumentOutOfRangeException(nameof(languageName), actualValue: languageName, message: "Only C#, F# and VB.NET project are supported.")
};
var processInfo = ProcessRunner.CreateProcess("dotnet", $"new \"{templateName}\" -o \"{outputPath}\" --language \"{language}\"", captureOutput: true, displayWindow: false);
var restoreResult = await processInfo.Result;
output.WriteLine(string.Join(Environment.NewLine, restoreResult.OutputLines));
return restoreResult.ExitCode;
}
public static async Task<int> PerformBuildAsync(string workspaceFilePath, ITestOutputHelper output)
{
var workspacePath = Path.IsPathRooted(workspaceFilePath)
? workspaceFilePath
: Path.Combine(TestProjectsPathHelper.GetProjectsDirectory(), workspaceFilePath);
var processInfo = ProcessRunner.CreateProcess("dotnet", $"build \"{workspacePath}\"", captureOutput: true, displayWindow: false);
var restoreResult = await processInfo.Result;
output.WriteLine(string.Join(Environment.NewLine, restoreResult.OutputLines));
return restoreResult.ExitCode;
}
public static async Task<int> PerformRestoreAsync(string workspaceFilePath, ITestOutputHelper output)
{
var workspacePath = Path.IsPathRooted(workspaceFilePath)
? workspaceFilePath
: Path.Combine(TestProjectsPathHelper.GetProjectsDirectory(), workspaceFilePath);
var processInfo = ProcessRunner.CreateProcess("dotnet", $"restore \"{workspacePath}\"", captureOutput: true, displayWindow: false);
var restoreResult = await processInfo.Result;
output.WriteLine(string.Join(Environment.NewLine, restoreResult.OutputLines));
return restoreResult.ExitCode;
}
}
}