remove cross project reference from dotnet-add-p2p tests
This commit is contained in:
parent
5095981ec3
commit
35bc8e1cc1
3 changed files with 41 additions and 46 deletions
|
@ -3,17 +3,18 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Build.Construction;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Construction;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectJsonMigration
|
||||
{
|
||||
internal static class MSBuildExtensions
|
||||
public static class MSBuildExtensions
|
||||
{
|
||||
public static IEnumerable<string> GetEncompassedIncludes(this ProjectItemElement item,
|
||||
ProjectItemElement otherItem)
|
||||
ProjectItemElement otherItem, TextWriter trace = null)
|
||||
{
|
||||
if (otherItem.IsEquivalentToExceptIncludeAndExclude(item) &&
|
||||
if (otherItem.IsEquivalentToExceptIncludeAndExclude(item, trace) &&
|
||||
new HashSet<string>(otherItem.Excludes()).IsSubsetOf(new HashSet<string>(item.Excludes())))
|
||||
{
|
||||
return otherItem.IntersectIncludes(item);
|
||||
|
@ -22,37 +23,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
return Enumerable.Empty<string>();
|
||||
}
|
||||
|
||||
public static bool IsEquivalentTo(this ProjectItemElement item, ProjectItemElement otherItem)
|
||||
public static bool IsEquivalentTo(this ProjectItemElement item, ProjectItemElement otherItem, TextWriter trace = null)
|
||||
{
|
||||
// Different includes
|
||||
if (item.IntersectIncludes(otherItem).Count() != item.Includes().Count())
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.IncludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
#endif
|
||||
trace?.WriteLine(String.Format(LocalizableStrings.IncludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Different Excludes
|
||||
if (item.IntersectExcludes(otherItem).Count() != item.Excludes().Count())
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ExcludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
#endif
|
||||
trace?.WriteLine(String.Format(LocalizableStrings.ExcludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
return false;
|
||||
}
|
||||
|
||||
return item.IsEquivalentToExceptIncludeAndExclude(otherItem);
|
||||
return item.IsEquivalentToExceptIncludeAndExclude(otherItem, trace);
|
||||
}
|
||||
|
||||
public static bool IsEquivalentToExceptIncludeAndExclude(this ProjectItemElement item, ProjectItemElement otherItem)
|
||||
public static bool IsEquivalentToExceptIncludeAndExclude(this ProjectItemElement item, ProjectItemElement otherItem, TextWriter trace = null)
|
||||
{
|
||||
// Different remove
|
||||
if (item.Remove != otherItem.Remove)
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.RemovesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
#endif
|
||||
trace?.WriteLine(String.Format(LocalizableStrings.RemovesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -67,17 +62,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
var otherMetadata = itemToCompare.GetMetadataWithName(metadata.Name);
|
||||
if (otherMetadata == null)
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataDoesntExist, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value));
|
||||
#endif
|
||||
trace?.WriteLine(String.Format(LocalizableStrings.MetadataDoesntExist, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!metadata.ValueEquals(otherMetadata))
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataHasAnotherValue, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value, otherMetadata.Value));
|
||||
#endif
|
||||
trace?.WriteLine(String.Format(LocalizableStrings.MetadataHasAnotherValue, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value, otherMetadata.Value));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -175,11 +166,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
return metadata.Value.Equals(otherMetadata.Value, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public static void AddMetadata(this ProjectItemElement item, ICollection<ProjectMetadataElement> metadataElements)
|
||||
public static void AddMetadata(this ProjectItemElement item, ICollection<ProjectMetadataElement> metadataElements, TextWriter trace = null)
|
||||
{
|
||||
foreach (var metadata in metadataElements)
|
||||
{
|
||||
item.AddMetadata(metadata);
|
||||
item.AddMetadata(metadata, trace);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +187,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
return item.Metadata.FirstOrDefault(m => m.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public static void AddMetadata(this ProjectItemElement item, ProjectMetadataElement metadata)
|
||||
public static void AddMetadata(this ProjectItemElement item, ProjectMetadataElement metadata, TextWriter trace = null)
|
||||
{
|
||||
var existingMetadata = item.GetMetadataWithName(metadata.Name);
|
||||
|
||||
|
@ -207,9 +198,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
|
||||
if (existingMetadata == default(ProjectMetadataElement))
|
||||
{
|
||||
#if !DISABLE_TRACE
|
||||
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.AddingMetadataToItem, nameof(AddMetadata), item.ItemType, metadata.Name, metadata.Value, metadata.Condition));
|
||||
#endif
|
||||
trace?.WriteLine(String.Format(LocalizableStrings.AddingMetadataToItem, nameof(AddMetadata), item.ItemType, metadata.Name, metadata.Value, metadata.Condition));
|
||||
var metametadata = item.AddMetadata(metadata.Name, metadata.Value);
|
||||
metametadata.Condition = metadata.Condition;
|
||||
metametadata.ExpressedAsAttribute = metadata.ExpressedAsAttribute;
|
||||
|
|
|
@ -2,37 +2,47 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectJsonMigration
|
||||
{
|
||||
internal class MigrationTrace
|
||||
internal class MigrationTrace : TextWriter
|
||||
{
|
||||
public static MigrationTrace Instance { get; set; }
|
||||
|
||||
public string EnableEnvironmentVariable => "DOTNET_MIGRATION_TRACE";
|
||||
public bool IsEnabled { get; private set; }
|
||||
|
||||
private TextWriter _underlyingWriter;
|
||||
|
||||
static MigrationTrace ()
|
||||
{
|
||||
Instance = new MigrationTrace();
|
||||
}
|
||||
|
||||
public string EnableEnvironmentVariable => "DOTNET_MIGRATION_TRACE";
|
||||
|
||||
public bool IsEnabled
|
||||
public MigrationTrace()
|
||||
{
|
||||
get
|
||||
{
|
||||
#if DEBUG
|
||||
return true;
|
||||
#else
|
||||
return Environment.GetEnvironmentVariable(EnableEnvironmentVariable) != null;
|
||||
#endif
|
||||
}
|
||||
_underlyingWriter = Console.Out;
|
||||
IsEnabled = IsEnabledValue();
|
||||
}
|
||||
|
||||
public void WriteLine(string message)
|
||||
private bool IsEnabledValue()
|
||||
{
|
||||
#if DEBUG
|
||||
return true;
|
||||
#else
|
||||
return Environment.GetEnvironmentVariable(EnableEnvironmentVariable) != null;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override Encoding Encoding => _underlyingWriter.Encoding;
|
||||
|
||||
public override void Write(char value)
|
||||
{
|
||||
if (IsEnabled)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
_underlyingWriter.Write(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,9 @@
|
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||
<AssemblyName>dotnet-add-p2p.Tests</AssemblyName>
|
||||
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
|
||||
<DefineConstants>$(DefineConstants);DISABLE_TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" />
|
||||
<Compile Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs">
|
||||
<Link>src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs</Link>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="**\*.resx" />
|
||||
<EmbeddedResource Include="compiler\resources\**\*" />
|
||||
</ItemGroup>
|
||||
|
|
Loading…
Reference in a new issue