Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ward <matt.ward@microsoft.com>2020-01-03 17:02:05 +0300
committerMatt Ward <ward.matt@gmail.com>2020-01-18 16:38:13 +0300
commitdd49233341410b9eb5e04b53301615a7b5a39221 (patch)
tree4caba5518884e744c1a3f9330eca7193137bc8c7
parent30e46306561aad819166523a1de8351bac6a5afb (diff)
[NuGet] Fix analyzers not used by SDK style projects
Analyzer items were not being resolved so no analyzers were being passed to the type system for SDK style projects. Non-SDK style PackageReference projects were resolving Analyzer items. Projects that use a packages.config have to explicitly use Analzyer items in the project file. To fix this the CoreCompileDependsOn targets is changed to include the ResolveLockFileAnalyzers which resolves the Analyzer items. This was already working for non-SDK style PackageReference projects since the NuGet addin was adding the ResolveNuGetPackageAssets target to the CoreCompileDependsOn targets and that resolves the Analyzer items. Fixes VSTS #1047893 - Analyzers not used by SDK style projects
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj1
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/AnalyzerTests.cs68
-rw-r--r--main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs7
-rw-r--r--main/tests/test-projects/StyleCopAnalyzer/NetFramework/NetFramework.csproj39
-rw-r--r--main/tests/test-projects/StyleCopAnalyzer/NetStandard/NetStandard.csproj13
-rw-r--r--main/tests/test-projects/StyleCopAnalyzer/StyleCopAnalyzer.sln23
6 files changed, 149 insertions, 2 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj
index b96a78138b..0e2ce50d9e 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj
@@ -160,6 +160,7 @@
<Compile Include="MonoDevelop.PackageManagement.Tests\UpdateMultipleNuGetPackagesActionTests.cs" />
<Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableUpdateMultipleNuGetPackagesAction.cs" />
<Compile Include="MonoDevelop.PackageManagement.Tests\MonoDevelopNuGetResourceProviderFactoryTests.cs" />
+ <Compile Include="MonoDevelop.PackageManagement.Tests\AnalyzerTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\MonoDevelop.Core\MonoDevelop.Core.csproj">
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/AnalyzerTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/AnalyzerTests.cs
new file mode 100644
index 0000000000..0bd05d19ce
--- /dev/null
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/AnalyzerTests.cs
@@ -0,0 +1,68 @@
+//
+// AnalyzerTests.cs
+//
+// Author:
+// Matt Ward <matt.ward@microsoft.com>
+//
+// Copyright (c) 2020 Microsoft Corporation
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System.Diagnostics;
+using System.Linq;
+using System.Threading.Tasks;
+using MonoDevelop.PackageManagement.Tests.Helpers;
+using MonoDevelop.Projects;
+using NUnit.Framework;
+using UnitTests;
+
+namespace MonoDevelop.PackageManagement.Tests
+{
+ [TestFixture]
+ public class AnalyzerTests : RestoreTestBase
+ {
+ /// <summary>
+ /// Tests that SDK and non-SDK project with PackageReferences resolves the Analyzers used by the project.
+ /// </summary>
+ [Test]
+ public async Task StyleCopAnalyzer ()
+ {
+ string solutionFileName = Util.GetSampleProject ("StyleCopAnalyzer", "StyleCopAnalyzer.sln");
+ solution = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solutionFileName);
+ CreateNuGetConfigFile (solution.BaseDirectory);
+ var netStandardProject = (DotNetProject)solution.FindProjectByName ("NetStandard");
+ var packageReferenceProject = (DotNetProject)solution.FindProjectByName ("NetFramework");
+
+ var process = Process.Start ("msbuild", $"/t:Restore /p:RestoreDisableParallel=true \"{solutionFileName}\"");
+ Assert.IsTrue (process.WaitForExit (120000), "Timeout restoring NuGet packages.");
+ Assert.AreEqual (0, process.ExitCode);
+
+ var netStandardProjectAnalyzers = await netStandardProject.GetAnalyzerFilesAsync (ConfigurationSelector.Default);
+ var packageReferenceProjectAnalyzers = await packageReferenceProject.GetAnalyzerFilesAsync (ConfigurationSelector.Default);
+
+ var netStandardProjectAnalyzerFileNames = netStandardProjectAnalyzers.Select (f => f.FileName).ToArray ();
+ var packageReferenceProjectAnalyzerFileNames = packageReferenceProjectAnalyzers.Select (f => f.FileName).ToArray ();
+
+ Assert.That (packageReferenceProjectAnalyzerFileNames, Contains.Item ("StyleCop.Analyzers.dll"));
+ Assert.That (packageReferenceProjectAnalyzerFileNames, Contains.Item ("StyleCop.Analyzers.CodeFixes.dll"));
+ Assert.That (netStandardProjectAnalyzerFileNames, Contains.Item ("StyleCop.Analyzers.dll"));
+ Assert.That (netStandardProjectAnalyzerFileNames, Contains.Item ("StyleCop.Analyzers.CodeFixes.dll"));
+ }
+ }
+}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs
index 05ff593afa..0272139f4b 100644
--- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs
+++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs
@@ -105,17 +105,20 @@ namespace MonoDevelop.PackageManagement
/// <summary>
/// Ensures any NuGet package content files are included when CoreCompileDependsOn is evaluated.
- /// Visual Studio 2017 does not run the RunProductContentAssets target directly but runs a set of
+ /// Visual Studio 2017 does not run the RunProduceContentAssets target directly but runs a set of
/// targets which indirectly run RunProductContentAssets. Have to run ResolvePackageAssets before
/// RunProduceContentAssets since the .NET Core 3.0 SDK will not run RunProduceContentAssets if no
/// content items are available to process. The content items are generated by ResolvePackageAssets.
/// Whilst RunProduceContentAssets depends on ResolvePackageAssets it will not run ResolvePackageAssets
/// since the RunProduceContentAssets condition is false. This was not the case in .NET Core 2.1 SDK
/// where there was no condition for the RunProduceContentAssets.
+ ///
+ /// ResolveLockFileAnalyzers is used to generate Analyzer msbuild items for the type system service.
+ /// For non-SDK style projects the Analyzer MSBuild items are generated by ResolveNuGetPackageAssets.
/// </summary>
Task<TargetEvaluationResult> OnRunDotNetCoreProjectTarget (ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context)
{
- target += ";ResolvePackageAssets;RunProduceContentAssets";
+ target += ";ResolvePackageAssets;ResolveLockFileAnalyzers;RunProduceContentAssets";
return base.OnRunTarget (monitor, target, configuration, context);
}
diff --git a/main/tests/test-projects/StyleCopAnalyzer/NetFramework/NetFramework.csproj b/main/tests/test-projects/StyleCopAnalyzer/NetFramework/NetFramework.csproj
new file mode 100644
index 0000000000..056b000a9d
--- /dev/null
+++ b/main/tests/test-projects/StyleCopAnalyzer/NetFramework/NetFramework.csproj
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{B24B963D-E5CD-46CA-907D-477B205C835B}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <RootNamespace>NetFramework</RootNamespace>
+ <AssemblyName>NetFramework</AssemblyName>
+ <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release</OutputPath>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <ConsolePause>false</ConsolePause>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ </ItemGroup>
+ <ItemGroup>
+ <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+</Project> \ No newline at end of file
diff --git a/main/tests/test-projects/StyleCopAnalyzer/NetStandard/NetStandard.csproj b/main/tests/test-projects/StyleCopAnalyzer/NetStandard/NetStandard.csproj
new file mode 100644
index 0000000000..d59e138776
--- /dev/null
+++ b/main/tests/test-projects/StyleCopAnalyzer/NetStandard/NetStandard.csproj
@@ -0,0 +1,13 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard2.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
+ </ItemGroup>
+</Project>
diff --git a/main/tests/test-projects/StyleCopAnalyzer/StyleCopAnalyzer.sln b/main/tests/test-projects/StyleCopAnalyzer/StyleCopAnalyzer.sln
new file mode 100644
index 0000000000..9f21d7ca09
--- /dev/null
+++ b/main/tests/test-projects/StyleCopAnalyzer/StyleCopAnalyzer.sln
@@ -0,0 +1,23 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetFramework", "NetFramework\NetFramework.csproj", "{B24B963D-E5CD-46CA-907D-477B205C835B}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetStandard", "NetStandard\NetStandard.csproj", "{C8CEDB3E-C6DD-475A-B365-48D47958CE4B}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B24B963D-E5CD-46CA-907D-477B205C835B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B24B963D-E5CD-46CA-907D-477B205C835B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B24B963D-E5CD-46CA-907D-477B205C835B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B24B963D-E5CD-46CA-907D-477B205C835B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C8CEDB3E-C6DD-475A-B365-48D47958CE4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C8CEDB3E-C6DD-475A-B365-48D47958CE4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C8CEDB3E-C6DD-475A-B365-48D47958CE4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C8CEDB3E-C6DD-475A-B365-48D47958CE4B}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal