-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue a warning on restore about obsolete DotNetCliToolReference
- Loading branch information
Nate McMaster
committed
Mar 22, 2018
1 parent
4d1111e
commit cabf60c
Showing
4 changed files
with
132 additions
and
28 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ObsoleteReferences.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.NET.ObsoleteReferences.targets | ||
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||
created a backup copy. Incorrect changes to this file will make it | ||
impossible to load or build your projects from the command-line or the IDE. | ||
Copyright (c) .NET Foundation. All rights reserved. | ||
*********************************************************************************************** | ||
--> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<PropertyGroup> | ||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
</PropertyGroup> | ||
|
||
<Target Name="_WarnAboutObsoleteDotNetCliToolReferences" BeforeTargets="CollectPackageReferences"> | ||
<ItemGroup> | ||
<_ReferenceToObsoleteDotNetCliTool Include="@(DotNetCliToolReference)" /> | ||
<DotNetCliToolReference Remove="@(BundledDotNetCliToolReference)" /> | ||
<_ReferenceToObsoleteDotNetCliTool Remove="@(DotNetCliToolReference)" /> | ||
</ItemGroup> | ||
|
||
<Warning | ||
Code="DOTNET1018" | ||
Text="Using DotNetCliToolReference to reference '%(_ReferenceToObsoleteDotNetCliTool.Identity)' is obsolete and can be removed from this project. This tool is bundled by default in the .NET Core SDK." | ||
Condition=" '%(_ReferenceToObsoleteDotNetCliTool.Identity)' != '' " /> | ||
</Target> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToIgnoreObsoleteDotNetCliToolPackages.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.IO; | ||
using System.Linq; | ||
using System.Xml.Linq; | ||
using FluentAssertions; | ||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.ProjectConstruction; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.NET.Restore.Tests | ||
{ | ||
public class GivenThatWeWantToIgnoreObsoleteDotNetCliToolPackages : SdkTest | ||
{ | ||
public GivenThatWeWantToIgnoreObsoleteDotNetCliToolPackages(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void It_issues_warning_and_skips_restore_for_obsolete_DotNetCliToolReference() | ||
{ | ||
const string obsoletePackageId = "Banana.CommandLineTool"; | ||
|
||
TestProject toolProject = new TestProject() | ||
{ | ||
Name = "ObsoleteCliToolRefRestoreProject", | ||
IsSdkProject = true, | ||
TargetFrameworks = "netstandard2.0", | ||
}; | ||
|
||
toolProject.DotNetCliToolReferences.Add(new TestPackageReference(obsoletePackageId, "99.99.99", null)); | ||
|
||
var toolProjectInstance = _testAssetsManager.CreateTestProject(toolProject, identifier: toolProject.Name) | ||
.WithProjectChanges(project => | ||
{ | ||
var ns = project.Root.Name.Namespace; | ||
|
||
var itemGroup = new XElement(ns + "ItemGroup"); | ||
project.Root.Add(itemGroup); | ||
|
||
itemGroup.Add(new XElement(ns + "BundledDotNetCliToolReference", | ||
new XAttribute("Include", obsoletePackageId))); | ||
}); | ||
|
||
NuGetConfigWriter.Write(toolProjectInstance.TestRoot, NuGetConfigWriter.DotnetCoreMyGetFeed); | ||
|
||
toolProjectInstance.Restore(Log, toolProject.Name, "/v:n"); | ||
|
||
var restoreCommand = toolProjectInstance.GetRestoreCommand(Log, toolProject.Name); | ||
restoreCommand.Execute("/v:n").Should() | ||
.Pass() | ||
.And | ||
.HaveStdOutContaining($"warning DOTNET1018: Using DotNetCliToolReference to reference '{obsoletePackageId}' is obsolete and can be removed from this project. This tool is bundled by default in the .NET Core SDK."); | ||
|
||
string toolAssetsFilePath = Path.Combine(TestContext.Current.NuGetCachePath, ".tools", toolProject.Name.ToLowerInvariant(), "99.99.99", toolProject.TargetFrameworks, "project.assets.json"); | ||
Assert.False(File.Exists(toolAssetsFilePath), "Tool assets path should not have been generated"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters