Applying suggesting fix from https://github.com/dotnet/aspnetcore/issues/10422 and use "CopyToOutputDirectory" rather than "CopyToPublishDirectory" (#20274)

This commit is contained in:
TeBeCo 2020-04-08 18:57:32 +02:00 committed by GitHub
parent ada3bdf45d
commit f3963e7cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 22 deletions

View File

@ -5,15 +5,12 @@ using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Analyzer.Testing;
using Microsoft.AspNetCore.Testing;
using Microsoft.CodeAnalysis;
namespace Microsoft.AspNetCore.Analyzers
{
public abstract class AnalyzerTestBase
{
private static readonly string ProjectDirectory = GetProjectDirectory();
public TestSource Read(string source)
{
if (!source.EndsWith(".cs"))
@ -21,7 +18,7 @@ namespace Microsoft.AspNetCore.Analyzers
source = source + ".cs";
}
var filePath = Path.Combine(ProjectDirectory, "TestFiles", GetType().Name, source);
var filePath = Path.Combine(AppContext.BaseDirectory, "TestFiles", GetType().Name, source);
if (!File.Exists(filePath))
{
throw new FileNotFoundException($"TestFile {source} could not be found at {filePath}.", filePath);
@ -46,22 +43,5 @@ namespace Microsoft.AspNetCore.Analyzers
{
return CreateProject(source).GetCompilationAsync();
}
private static string GetProjectDirectory()
{
// On helix we use the published test files
if (SkipOnHelixAttribute.OnHelix())
{
return AppContext.BaseDirectory;
}
// This test code needs to be updated to support distributed testing.
// See https://github.com/dotnet/aspnetcore/issues/10422
#pragma warning disable 0618
var solutionDirectory = TestPathUtilities.GetSolutionRootDirectory("Analyzers");
#pragma warning restore 0618
var projectDirectory = Path.Combine(solutionDirectory, "Analyzers", "test");
return projectDirectory;
}
}
}

View File

@ -8,7 +8,7 @@
<ItemGroup>
<Compile Include="$(SharedSourceRoot)test\SkipOnHelixAttribute.cs" />
<Content Include="TestFiles\**\*.*" CopyToPublishDirectory="PreserveNewest" />
<Content Include="TestFiles\**\*.*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>