Revert "When Library add reference to NETStandardLib if not present"
This reverts commit 57d79bb2d3
.
This commit is contained in:
parent
57d79bb2d3
commit
875e275e38
12 changed files with 37 additions and 129 deletions
|
@ -1 +0,0 @@
|
||||||
noautobuild
|
|
|
@ -1,5 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"frameworks": {
|
|
||||||
"netstandard1.3": {
|
|
||||||
"dependencies": {
|
|
||||||
"System.AppContext": "4.1.0",
|
|
||||||
"NETStandard.Library": "1.5.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
noautobuild
|
|
|
@ -1,5 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"frameworks": {
|
|
||||||
"netstandard1.3": {
|
|
||||||
"dependencies": {
|
|
||||||
"System.AppContext": "4.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,8 +19,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk";
|
public const string TestSdkPackageName = "Microsoft.NET.Test.Sdk";
|
||||||
public const string XUnitPackageName = "xunit";
|
public const string XUnitPackageName = "xunit";
|
||||||
public const string XUnitRunnerPackageName = "xunit.runner.visualstudio";
|
public const string XUnitRunnerPackageName = "xunit.runner.visualstudio";
|
||||||
public const string NetStandardPackageName = "NETStandard.Library";
|
|
||||||
public const string NetStandardPackageVersion = "1.6.0";
|
|
||||||
|
|
||||||
public static readonly IDictionary<string, PackageDependencyInfo> ProjectDependencyPackages =
|
public static readonly IDictionary<string, PackageDependencyInfo> ProjectDependencyPackages =
|
||||||
new Dictionary<string, PackageDependencyInfo> {
|
new Dictionary<string, PackageDependencyInfo> {
|
||||||
|
|
|
@ -13,59 +13,59 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
{
|
{
|
||||||
public static ProjectType GetProjectType(this Project project)
|
public static ProjectType GetProjectType(this Project project)
|
||||||
{
|
{
|
||||||
ProjectType projectType = ProjectType.Library;
|
var projectType = ProjectType.Console;
|
||||||
if (project.IsTestProject)
|
if (project.IsWebProject())
|
||||||
{
|
|
||||||
projectType = ProjectType.Test;
|
|
||||||
}
|
|
||||||
else if (project.HasEntryPoint())
|
|
||||||
{
|
|
||||||
if (project.HasDependency(ContainingName(".AspNetCore.")))
|
|
||||||
{
|
{
|
||||||
projectType = ProjectType.Web;
|
projectType = ProjectType.Web;
|
||||||
}
|
}
|
||||||
else
|
else if (project.IsTestProject)
|
||||||
{
|
{
|
||||||
projectType = ProjectType.Console;
|
projectType = ProjectType.Test;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectType;
|
return projectType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool HasEntryPoint(this Project project)
|
private static bool IsWebProject(this Project project)
|
||||||
{
|
{
|
||||||
return project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault();
|
if(project.IsTestProject)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Func<ProjectLibraryDependency, bool> ContainingName(string nameSegment)
|
var isExecutable = project.GetCompilerOptions(null, "Debug").EmitEntryPoint.GetValueOrDefault();
|
||||||
{
|
if (isExecutable
|
||||||
return x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1;
|
&& project.HasAnyPackageContainingName(".AspNetCore."))
|
||||||
}
|
|
||||||
|
|
||||||
public static bool HasDependency(this Project project, Func<ProjectLibraryDependency, bool> pred)
|
|
||||||
{
|
|
||||||
if (HasAnyDependency(project.Dependencies, pred))
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var tf in project.GetTargetFrameworks())
|
|
||||||
{
|
|
||||||
if(HasAnyDependency(tf.Dependencies, pred))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool HasAnyDependency(
|
private static bool HasAnyPackageContainingName(this Project project, string nameSegment)
|
||||||
IEnumerable<ProjectLibraryDependency> dependencies,
|
|
||||||
Func<ProjectLibraryDependency, bool> pred)
|
|
||||||
{
|
{
|
||||||
return dependencies.Any(pred);
|
var containsPackageName = HasAnyPackageContainingName(
|
||||||
|
new ReadOnlyCollection<ProjectLibraryDependency>(project.Dependencies),
|
||||||
|
nameSegment);
|
||||||
|
foreach (var tf in project.GetTargetFrameworks())
|
||||||
|
{
|
||||||
|
if(containsPackageName)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
containsPackageName = HasAnyPackageContainingName(tf.Dependencies, nameSegment);
|
||||||
|
}
|
||||||
|
|
||||||
|
return containsPackageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasAnyPackageContainingName(
|
||||||
|
IReadOnlyList<ProjectLibraryDependency> dependencies,
|
||||||
|
string nameSegment)
|
||||||
|
{
|
||||||
|
return dependencies.Any(x => x.Name.IndexOf(nameSegment, StringComparison.OrdinalIgnoreCase) > -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,8 +3,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
internal enum ProjectType
|
internal enum ProjectType
|
||||||
{
|
{
|
||||||
Console,
|
Console,
|
||||||
Library,
|
Web,
|
||||||
Test,
|
Test
|
||||||
Web
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -136,21 +136,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
|
||||||
mergeExisting: false);
|
mergeExisting: false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProjectType.Library:
|
|
||||||
if (!project.HasDependency(
|
|
||||||
(dep) => dep.Name.Trim().ToLower() == PackageConstants.NetStandardPackageName.ToLower()))
|
|
||||||
{
|
|
||||||
_transformApplicator.Execute(
|
|
||||||
PackageDependencyInfoTransform().Transform(
|
|
||||||
new PackageDependencyInfo
|
|
||||||
{
|
|
||||||
Name = PackageConstants.NetStandardPackageName,
|
|
||||||
Version = PackageConstants.NetStandardPackageVersion
|
|
||||||
}),
|
|
||||||
noFrameworkPackageReferenceItemGroup,
|
|
||||||
mergeExisting: true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,36 +347,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188"));
|
i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1188"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(@"
|
|
||||||
{
|
|
||||||
""frameworks"": {
|
|
||||||
""netstandard1.3"": {
|
|
||||||
""dependencies"": {
|
|
||||||
""System.AppContext"": ""4.1.0"",
|
|
||||||
""NETStandard.Library"": ""1.5.0""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}")]
|
|
||||||
[InlineData(@"
|
|
||||||
{
|
|
||||||
""frameworks"": {
|
|
||||||
""netstandard1.3"": {
|
|
||||||
""dependencies"": {
|
|
||||||
""System.AppContext"": ""4.1.0""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}")]
|
|
||||||
public void It_migrates_library_and_does_not_double_netstandard_ref(string pjContent)
|
|
||||||
{
|
|
||||||
var mockProj = RunPackageDependenciesRuleOnPj(pjContent);
|
|
||||||
|
|
||||||
mockProj.Items.Should().ContainSingle(
|
|
||||||
i => (i.Include == "NETStandard.Library" && i.ItemType == "PackageReference"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple<string, string, string>[] packageSpecs)
|
private void EmitsPackageReferences(ProjectRootElement mockProj, params Tuple<string, string, string>[] packageSpecs)
|
||||||
{
|
{
|
||||||
foreach (var packageSpec in packageSpecs)
|
foreach (var packageSpec in packageSpecs)
|
||||||
|
|
|
@ -423,19 +423,6 @@ namespace Microsoft.DotNet.Migration.Tests
|
||||||
.Count().Should().Be(1);
|
.Count().Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("LibraryWithoutNetStandardLibRef")]
|
|
||||||
[InlineData("LibraryWithNetStandardLibRef")]
|
|
||||||
public void It_migrates_and_builds_library(string projectName)
|
|
||||||
{
|
|
||||||
var projectDirectory = TestAssetsManager.CreateTestInstance(projectName,
|
|
||||||
callingMethod: $"{nameof(It_migrates_and_builds_library)}-projectName").Path;
|
|
||||||
|
|
||||||
MigrateProject(projectDirectory);
|
|
||||||
Restore(projectDirectory, projectName);
|
|
||||||
BuildMSBuild(projectDirectory, projectName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent)
|
private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent)
|
||||||
{
|
{
|
||||||
if (projectName != null)
|
if (projectName != null)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue