public void PackageErrorsAreSet(string targetFramework) { var designTimeArgs = GetDesignTimeMSBuildArgs(); if (designTimeArgs == null) { // Design-time targets couldn't be found return; } var testProject = new TestProject() { Name = "DesignTimePackageDependencies", TargetFrameworks = targetFramework, IsSdkProject = true }; // Downgrade will cause an error testProject.AdditionalProperties["ContinueOnError"] = "ErrorAndContinue"; testProject.PackageReferences.Add(new TestPackageReference("NuGet.Commands", "4.0.0")); testProject.PackageReferences.Add(new TestPackageReference("NuGet.Packaging", "3.5.0")); var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework); new RestoreCommand(testAsset) .Execute() .Should() .Fail(); var getValuesCommand = new GetValuesCommand(testAsset, "_PackageDependenciesDesignTime", GetValuesCommand.ValueType.Item); getValuesCommand.ShouldRestore = false; getValuesCommand.DependsOnTargets = "ResolvePackageDependenciesDesignTime"; getValuesCommand.MetadataNames = new List <string>() { "DiagnosticLevel" }; getValuesCommand .WithWorkingDirectory(testAsset.TestRoot) .Execute(designTimeArgs) .Should() .Fail(); var valuesWithMetadata = getValuesCommand.GetValuesWithMetadata(); var nugetPackagingMetadata = valuesWithMetadata.Single(kvp => kvp.value.Equals("NuGet.Packaging/3.5.0")).metadata; nugetPackagingMetadata["DiagnosticLevel"].Should().Be("Error"); }
public void It_resolves_analyzers_correctly(string language, string testAssetName) { var asset = _testAssetsManager .CopyTestAsset(testAssetName, identifier: language) .WithSource() .WithProjectChanges(project => { var ns = project.Root.Name.Namespace; project.Root.Add( new XElement(ns + "ItemGroup", new XElement(ns + "PackageReference", new XAttribute("Include", "Microsoft.DependencyValidation.Analyzers"), new XAttribute("Version", "0.9.0")), new XElement(ns + "PackageReference", new XAttribute("Include", "Microsoft.CodeQuality.Analyzers"), new XAttribute("Version", "2.6.0")))); }); var command = new GetValuesCommand( Log, Path.Combine(asset.Path, "TestApp"), ToolsetInfo.CurrentTargetFramework, "Analyzer", GetValuesCommand.ValueType.Item); command .WithWorkingDirectory(asset.Path) .Execute("/bl") .Should().Pass(); var analyzers = command.GetValues(); switch (language) { case "C#": analyzers.Select(x => GetPackageAndPath(x)).Should().BeEquivalentTo( ("Microsoft.NET.Sdk", (string)null, "analyzers/Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll"), ("Microsoft.NET.Sdk", (string)null, "analyzers/Microsoft.CodeAnalysis.NetAnalyzers.dll"), ("microsoft.netcore.app.ref", (string)null, "analyzers/dotnet/cs/System.Text.Json.SourceGeneration.dll"), ("microsoft.netcore.app.ref", (string)null, "analyzers/dotnet/cs/System.Text.RegularExpressions.Generator.dll"), ("microsoft.codequality.analyzers", "2.6.0", "analyzers/dotnet/cs/Microsoft.CodeQuality.Analyzers.dll"), ("microsoft.codequality.analyzers", "2.6.0", "analyzers/dotnet/cs/Microsoft.CodeQuality.CSharp.Analyzers.dll"), ("microsoft.dependencyvalidation.analyzers", "0.9.0", "analyzers/dotnet/Microsoft.DependencyValidation.Analyzers.dll") ); break; case "VB": analyzers.Select(x => GetPackageAndPath(x)).Should().BeEquivalentTo( ("Microsoft.NET.Sdk", (string)null, "analyzers/Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers.dll"), ("Microsoft.NET.Sdk", (string)null, "analyzers/Microsoft.CodeAnalysis.NetAnalyzers.dll"), ("microsoft.codequality.analyzers", "2.6.0", "analyzers/dotnet/vb/Microsoft.CodeQuality.Analyzers.dll"), ("microsoft.codequality.analyzers", "2.6.0", "analyzers/dotnet/vb/Microsoft.CodeQuality.VisualBasic.Analyzers.dll"), ("microsoft.dependencyvalidation.analyzers", "0.9.0", "analyzers/dotnet/Microsoft.DependencyValidation.Analyzers.dll") ); break; case "F#": analyzers.Should().BeEmpty(); break; default: throw new ArgumentOutOfRangeException(nameof(language)); } }