提交 8dc9e41f 编写于 作者: S Sam Harwell

Updated annotations based on code review feedback

上级 911faded
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Text; using System.Text;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
...@@ -174,7 +175,7 @@ internal void AppendSwitchWithSplitting(string switchName, string? parameter, st ...@@ -174,7 +175,7 @@ internal void AppendSwitchWithSplitting(string switchName, string? parameter, st
/// even if it contains the separators and white space only /// even if it contains the separators and white space only
/// Split on the characters provided. /// Split on the characters provided.
/// </summary> /// </summary>
internal static bool IsParameterEmpty(string parameter, params char[] splitOn) internal static bool IsParameterEmpty([NotNullWhen(false)] string? parameter, params char[] splitOn)
{ {
if (parameter != null) if (parameter != null)
{ {
...@@ -202,12 +203,12 @@ internal void AppendSwitchIfNotNull ...@@ -202,12 +203,12 @@ internal void AppendSwitchIfNotNull
( (
string switchName, string switchName,
ITaskItem[]? parameters, ITaskItem[]? parameters,
string[] metadataNames, string[]? metadataNames,
bool[]? treatAsFlags // May be null. In this case no metadata are treated as flags. bool[]? treatAsFlags // May be null. In this case no metadata are treated as flags.
) )
{ {
Debug.Assert(treatAsFlags == null Debug.Assert(treatAsFlags == null
|| (metadataNames.Length == treatAsFlags.Length), || (metadataNames?.Length == treatAsFlags.Length),
"metadataNames and treatAsFlags should have the same length."); "metadataNames and treatAsFlags should have the same length.");
if (parameters != null) if (parameters != null)
......
...@@ -11,25 +11,20 @@ ...@@ -11,25 +11,20 @@
using System.Linq; using System.Linq;
using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities; using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit; using Xunit;
namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests
{ {
public class IntegrationTests : TestBase public class IntegrationTests : TestBase
{ {
private static readonly string s_msbuildDirectory; private static readonly string? s_msbuildDirectory;
private static readonly string? s_msbuildExecutable;
static IntegrationTests() static IntegrationTests()
{ {
s_msbuildDirectory = DesktopTestHelpers.GetMSBuildDirectory(); s_msbuildDirectory = DesktopTestHelpers.GetMSBuildDirectory();
if (s_msbuildDirectory != null)
{
s_msbuildExecutable = Path.Combine(s_msbuildDirectory, "MSBuild.exe");
}
} }
private readonly string _msbuildExecutable;
private readonly TempDirectory _tempDirectory; private readonly TempDirectory _tempDirectory;
private readonly List<Process> _existingServerList = new List<Process>(); private readonly List<Process> _existingServerList = new List<Process>();
private readonly string _buildTaskDll; private readonly string _buildTaskDll;
...@@ -41,6 +36,7 @@ public IntegrationTests() ...@@ -41,6 +36,7 @@ public IntegrationTests()
throw new InvalidOperationException("Could not locate MSBuild"); throw new InvalidOperationException("Could not locate MSBuild");
} }
_msbuildExecutable = Path.Combine(s_msbuildDirectory, "MSBuild.exe");
_tempDirectory = Temp.CreateDirectory(); _tempDirectory = Temp.CreateDirectory();
_existingServerList = Process.GetProcessesByName(Path.GetFileNameWithoutExtension("VBCSCompiler")).ToList(); _existingServerList = Process.GetProcessesByName(Path.GetFileNameWithoutExtension("VBCSCompiler")).ToList();
_buildTaskDll = typeof(ManagedCompiler).Assembly.Location; _buildTaskDll = typeof(ManagedCompiler).Assembly.Location;
...@@ -409,10 +405,8 @@ End Class ...@@ -409,10 +405,8 @@ End Class
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/1445")] [Fact(Skip = "https://github.com/dotnet/roslyn/issues/1445")]
public void SimpleMSBuild() public void SimpleMSBuild()
{ {
RoslynDebug.Assert(s_msbuildExecutable is object);
string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseSharedCompilation=false /p:UseRoslyn=1 HelloSolution.sln"); string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseSharedCompilation=false /p:UseRoslyn=1 HelloSolution.sln");
var result = RunCommandLineCompiler(s_msbuildExecutable, arguments, _tempDirectory, SimpleMsBuildFiles); var result = RunCommandLineCompiler(_msbuildExecutable, arguments, _tempDirectory, SimpleMsBuildFiles);
using (var resultFile = GetResultFile(_tempDirectory, @"bin\debug\helloproj.exe")) using (var resultFile = GetResultFile(_tempDirectory, @"bin\debug\helloproj.exe"))
{ {
...@@ -610,10 +604,8 @@ End Class ...@@ -610,10 +604,8 @@ End Class
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/16301")] [Fact(Skip = "https://github.com/dotnet/roslyn/issues/16301")]
public void ReportAnalyzerMSBuild() public void ReportAnalyzerMSBuild()
{ {
RoslynDebug.Assert(s_msbuildExecutable is object);
string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseSharedCompilation=false /p:UseRoslyn=1 HelloSolution.sln"); string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseSharedCompilation=false /p:UseRoslyn=1 HelloSolution.sln");
var result = RunCommandLineCompiler(s_msbuildExecutable, arguments, _tempDirectory, ReportAnalyzerMsBuildFiles, var result = RunCommandLineCompiler(_msbuildExecutable, arguments, _tempDirectory, ReportAnalyzerMsBuildFiles,
new Dictionary<string, string> new Dictionary<string, string>
{ { "MyMSBuildToolsPath", Path.GetDirectoryName(typeof(IntegrationTests).Assembly.Location) } }); { { "MyMSBuildToolsPath", Path.GetDirectoryName(typeof(IntegrationTests).Assembly.Location) } });
...@@ -624,8 +616,6 @@ public void ReportAnalyzerMSBuild() ...@@ -624,8 +616,6 @@ public void ReportAnalyzerMSBuild()
[Fact(Skip = "failing msbuild")] [Fact(Skip = "failing msbuild")]
public void SolutionWithPunctuation() public void SolutionWithPunctuation()
{ {
RoslynDebug.Assert(s_msbuildExecutable is object);
var testDir = _tempDirectory.CreateDirectory(@"SLN;!@(goo)'^1"); var testDir = _tempDirectory.CreateDirectory(@"SLN;!@(goo)'^1");
var slnFile = testDir.CreateFile("Console;!@(goo)'^(Application1.sln").WriteAllText( var slnFile = testDir.CreateFile("Console;!@(goo)'^(Application1.sln").WriteAllText(
@" @"
...@@ -790,7 +780,7 @@ public class Class1 ...@@ -790,7 +780,7 @@ public class Class1
} }
"); ");
var result = RunCommandLineCompiler(s_msbuildExecutable, "/p:UseSharedCompilation=false", testDir.Path); var result = RunCommandLineCompiler(_msbuildExecutable, "/p:UseSharedCompilation=false", testDir.Path);
Assert.Equal(0, result.ExitCode); Assert.Equal(0, result.ExitCode);
Assert.Equal("", result.Errors); Assert.Equal("", result.Errors);
} }
......
#if NET472 // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
#if NET472
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
...@@ -275,7 +282,7 @@ public override void Initialize(AnalysisContext context) ...@@ -275,7 +282,7 @@ public override void Initialize(AnalysisContext context)
return analyzerImage; return analyzerImage;
} }
public static string GetMSBuildDirectory() public static string? GetMSBuildDirectory()
{ {
var vsVersion = Environment.GetEnvironmentVariable("VisualStudioVersion") ?? "14.0"; var vsVersion = Environment.GetEnvironmentVariable("VisualStudioVersion") ?? "14.0";
using (var key = Registry.LocalMachine.OpenSubKey($@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\{vsVersion}", false)) using (var key = Registry.LocalMachine.OpenSubKey($@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\{vsVersion}", false))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册