Skip to content

Commit ff93c8b

Browse files
Copilotbaronfel
andcommitted
Scope BannedApiAnalyzer to src/Cli and fix all ProjectCollection violations
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
1 parent fe985de commit ff93c8b

File tree

51 files changed

+110
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+110
-130
lines changed

eng/Analyzers.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Project>
22
<ItemGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
33
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="all" Condition="'$(EnableStyleCopAnalyzer)' == 'true'" />
4-
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" PrivateAssets="all" />
4+
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" PrivateAssets="all" Condition="$(MSBuildProjectDirectory.Contains('src\Cli')) OR $(MSBuildProjectDirectory.Contains('src/Cli'))" />
55
</ItemGroup>
66

7-
<ItemGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
7+
<ItemGroup Condition="'$(DotNetBuildSourceOnly)' != 'true' AND ($(MSBuildProjectDirectory.Contains('src\Cli')) OR $(MSBuildProjectDirectory.Contains('src/Cli')))">
88
<AdditionalFiles Include="$(MSBuildThisFileDirectory)../BannedSymbols.txt" />
99
</ItemGroup>
1010
</Project>

src/Cli/dotnet/CliCompletion.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.CommandLine.Completions;
77
using Microsoft.Build.Evaluation;
8+
using Microsoft.DotNet.Cli.Extensions;
89
using Microsoft.DotNet.Cli.Utils;
910
using static System.Array;
1011

@@ -69,8 +70,9 @@ private static MsbuildProject GetMSBuildProject()
6970
{
7071
try
7172
{
73+
var (loggers, _) = ProjectInstanceExtensions.CreateLoggersWithTelemetry();
7274
return MsbuildProject.FromFileOrDirectory(
73-
new ProjectCollection(),
75+
new ProjectCollection(globalProperties: null, loggers: loggers, toolsetDefinitionLocations: ToolsetDefinitionLocations.Default),
7476
Directory.GetCurrentDirectory(), interactive: false);
7577
}
7678
catch (Exception e)

src/Cli/dotnet/CommandFactory/CommandResolution/ProjectToolsCommandResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ internal void GenerateDepsJsonFile(
385385
string? stdOut;
386386
string? stdErr;
387387

388-
var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([..args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption);
388+
var msbuildArgs = MSBuildArgs.AnalyzeMSBuildArguments([.. args], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, BuildCommandParser.TargetOption, BuildCommandParser.VerbosityOption);
389389
var forwardingAppWithoutLogging = new MSBuildForwardingAppWithoutLogging(msbuildArgs, msBuildExePath);
390390
if (forwardingAppWithoutLogging.ExecuteMSBuildOutOfProc)
391391
{

src/Cli/dotnet/Commands/Build/BuildCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class BuildCommand
1212
{
1313
public static CommandBase FromArgs(string[] args, string? msbuildPath = null)
1414
{
15-
var parseResult = Parser.Parse(["dotnet", "build", ..args]);
15+
var parseResult = Parser.Parse(["dotnet", "build", .. args]);
1616
return FromParseResult(parseResult, msbuildPath);
1717
}
1818

src/Cli/dotnet/Commands/Clean/CleanCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CleanCommand(MSBuildArgs msbuildArgs, string? msbuildPath = null) :
1313
{
1414
public static CommandBase FromArgs(string[] args, string? msbuildPath = null)
1515
{
16-
var result = Parser.Parse(["dotnet", "clean", ..args]);
16+
var result = Parser.Parse(["dotnet", "clean", .. args]);
1717
return FromParseResult(result, msbuildPath);
1818
}
1919

@@ -33,7 +33,7 @@ public static CommandBase FromParseResult(ParseResult result, string? msbuildPat
3333
NoWriteBuildMarkers = true,
3434
},
3535
static (msbuildArgs, msbuildPath) => new CleanCommand(msbuildArgs, msbuildPath),
36-
[ CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption ],
36+
[CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, CleanCommandParser.TargetOption, CleanCommandParser.VerbosityOption],
3737
result,
3838
msbuildPath
3939
);

src/Cli/dotnet/Commands/Format/FormatCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class FormatCommand(IEnumerable<string> argsToForward) : FormatForwarding
1313
{
1414
public static FormatCommand FromArgs(string[] args)
1515
{
16-
var result = Parser.Parse(["dotnet", "format", ..args]);
16+
var result = Parser.Parse(["dotnet", "format", .. args]);
1717
return FromParseResult(result);
1818
}
1919

src/Cli/dotnet/Commands/Hidden/Complete/CompleteCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static int Run(ParseResult parseResult)
1919

2020
public static int RunWithReporter(string[] args, IReporter reporter)
2121
{
22-
var result = Parser.Parse(["dotnet", "complete", ..args]);
22+
var result = Parser.Parse(["dotnet", "complete", .. args]);
2323
return RunWithReporter(result, reporter);
2424
}
2525

src/Cli/dotnet/Commands/Hidden/InternalReportInstallSuccess/InternalReportInstallSuccessCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static int Run(ParseResult parseResult)
2525

2626
public static void ProcessInputAndSendTelemetry(string[] args, ITelemetry telemetry)
2727
{
28-
var result = Parser.Parse(["dotnet", "internal-reportinstallsuccess", ..args]);
28+
var result = Parser.Parse(["dotnet", "internal-reportinstallsuccess", .. args]);
2929
ProcessInputAndSendTelemetry(result, telemetry);
3030
}
3131

src/Cli/dotnet/Commands/MSBuild/MSBuildCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ namespace Microsoft.DotNet.Cli.Commands.MSBuild;
1010
public class MSBuildCommand(
1111
IEnumerable<string> msbuildArgs,
1212
string? msbuildPath = null
13-
) : MSBuildForwardingApp(MSBuildArgs.AnalyzeMSBuildArguments([..msbuildArgs], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, MSBuildCommandParser.TargetOption, CommonOptions.VerbosityOption()), msbuildPath, includeLogo: true)
13+
) : MSBuildForwardingApp(MSBuildArgs.AnalyzeMSBuildArguments([.. msbuildArgs], CommonOptions.PropertiesOption, CommonOptions.RestorePropertiesOption, MSBuildCommandParser.TargetOption, CommonOptions.VerbosityOption()), msbuildPath, includeLogo: true)
1414
{
1515
public static MSBuildCommand FromArgs(string[] args, string? msbuildPath = null)
1616
{
17-
var result = Parser.Parse(["dotnet", "msbuild", ..args]);
17+
var result = Parser.Parse(["dotnet", "msbuild", .. args]);
1818
return FromParseResult(result, msbuildPath);
1919
}
2020

src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Globalization;

0 commit comments

Comments
 (0)