last touches
This commit is contained in:
parent
58fe57e315
commit
b8b7d98256
8 changed files with 32 additions and 35 deletions
|
@ -46,7 +46,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
|
||||||
|
|
||||||
public static ProjectItemGroupElement FindExistingUniformItemGroupWithCondition(this ProjectRootElement root, string projectItemElementType, string framework)
|
public static ProjectItemGroupElement FindExistingUniformItemGroupWithCondition(this ProjectRootElement root, string projectItemElementType, string framework)
|
||||||
{
|
{
|
||||||
return root.ItemGroupsReversed.FirstOrDefault((ig) => ig.IsConditionalOnFramework(framework) && ig.IsUniformItemElementType(projectItemElementType));
|
return root.ItemGroupsReversed.FirstOrDefault((itemGroup) => itemGroup.IsConditionalOnFramework(framework) && itemGroup.IsUniformItemElementType(projectItemElementType));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsUniformItemElementType(this ProjectItemGroupElement group, string projectItemElementType)
|
public static bool IsUniformItemElementType(this ProjectItemGroupElement group, string projectItemElementType)
|
||||||
|
|
|
@ -215,7 +215,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
|
||||||
int numberOfAddedReferences = 0;
|
int numberOfAddedReferences = 0;
|
||||||
const string ProjectItemElementType = "ProjectReference";
|
const string ProjectItemElementType = "ProjectReference";
|
||||||
|
|
||||||
ProjectItemGroupElement ig = null;
|
ProjectItemGroupElement itemGroup = root.FindUniformOrCreateItemGroupWithCondition(ProjectItemElementType, framework);
|
||||||
foreach (var @ref in refs.Select((r) => NormalizeSlashesForMsbuild(r)))
|
foreach (var @ref in refs.Select((r) => NormalizeSlashesForMsbuild(r)))
|
||||||
{
|
{
|
||||||
if (root.HasExistingItemWithCondition(framework, @ref))
|
if (root.HasExistingItemWithCondition(framework, @ref))
|
||||||
|
@ -225,8 +225,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
|
||||||
}
|
}
|
||||||
|
|
||||||
numberOfAddedReferences++;
|
numberOfAddedReferences++;
|
||||||
ig = ig ?? root.FindUniformOrCreateItemGroupWithCondition(ProjectItemElementType, framework);
|
itemGroup.AppendChild(root.CreateItemElement(ProjectItemElementType, @ref));
|
||||||
ig.AppendChild(root.CreateItemElement(ProjectItemElementType, @ref));
|
|
||||||
|
|
||||||
Reporter.Output.WriteLine($"Reference `{@ref}` added to the project.");
|
Reporter.Output.WriteLine($"Reference `{@ref}` added to the project.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,17 +18,17 @@ namespace Microsoft.DotNet.Tools.Add
|
||||||
{
|
{
|
||||||
public const string HelpText = @".NET Add Command
|
public const string HelpText = @".NET Add Command
|
||||||
|
|
||||||
Usage: dotnet add [options] [object] <command> [[--] <arg>...]]
|
Usage: dotnet add [options] <object> <command> [[--] <arg>...]]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h|--help Show help information
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
<object> The object of the operation. If a project file is not specified, it defaults to the current directory.
|
<object> The object of the operation. If a project file is not specified, it defaults to the current directory.
|
||||||
<command> Command to be executed on <object>.
|
<command> Command to be executed on <object>.
|
||||||
|
|
||||||
Options:
|
|
||||||
-h|--help Show help information
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
Any extra arguments passed to the command.
|
Any extra arguments passed to the command. Use `dotnet add <command> --help` to get help about these arguments.
|
||||||
|
|
||||||
Commands:
|
Commands:
|
||||||
p2p Add project to project (p2p) reference to a project";
|
p2p Add project to project (p2p) reference to a project";
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.0.0-preview4</VersionPrefix>
|
<VersionPrefix>1.0.0-preview4</VersionPrefix>
|
||||||
<TargetFramework>netcoreapp1.0</TargetFramework>
|
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||||
|
@ -10,11 +11,13 @@
|
||||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||||
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dotnet5.4</PackageTargetFallback>
|
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dotnet5.4</PackageTargetFallback>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="**\*.cs" Exclude="commands\dotnet-new\CSharp_Console\**;commands\dotnet-new\CSharp_Lib\**;commands\dotnet-new\CSharp_Mstest\**;commands\dotnet-new\CSharp_Web\**;commands\dotnet-new\CSharp_Xunittest\**;bin\**;obj\**;**\*.xproj;packages\**" />
|
<Compile Include="**\*.cs" Exclude="commands\dotnet-new\CSharp_Console\**;commands\dotnet-new\CSharp_Lib\**;commands\dotnet-new\CSharp_Mstest\**;commands\dotnet-new\CSharp_Web\**;commands\dotnet-new\CSharp_Xunittest\**;bin\**;obj\**;**\*.xproj;packages\**" />
|
||||||
<EmbeddedResource Include="**\*.resx" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
|
<EmbeddedResource Include="**\*.resx" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
|
||||||
<EmbeddedResource Include="commands\dotnet-new\CSharp_Console.zip;commands\dotnet-new\CSharp_Lib.zip;commands\dotnet-new\CSharp_Mstest.zip;commands\dotnet-new\CSharp_Xunittest.zip;commands\dotnet-new\CSharp_Web.zip;compiler\resources\**\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
|
<EmbeddedResource Include="commands\dotnet-new\CSharp_Console.zip;commands\dotnet-new\CSharp_Lib.zip;commands\dotnet-new\CSharp_Mstest.zip;commands\dotnet-new\CSharp_Xunittest.zip;commands\dotnet-new\CSharp_Web.zip;compiler\resources\**\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="../Microsoft.DotNet.Configurer/Microsoft.DotNet.Configurer.csproj" />
|
<ProjectReference Include="../Microsoft.DotNet.Configurer/Microsoft.DotNet.Configurer.csproj" />
|
||||||
<ProjectReference Include="../Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.ProjectJsonMigration.csproj" />
|
<ProjectReference Include="../Microsoft.DotNet.ProjectJsonMigration/Microsoft.DotNet.ProjectJsonMigration.csproj" />
|
||||||
|
@ -22,6 +25,7 @@
|
||||||
<ProjectReference Include="../Microsoft.DotNet.Archive/Microsoft.DotNet.Archive.csproj" />
|
<ProjectReference Include="../Microsoft.DotNet.Archive/Microsoft.DotNet.Archive.csproj" />
|
||||||
<ProjectReference Include="../Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj" />
|
<ProjectReference Include="../Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Sdk">
|
<PackageReference Include="Microsoft.NET.Sdk">
|
||||||
<Version>1.0.0-alpha-20161104-2</Version>
|
<Version>1.0.0-alpha-20161104-2</Version>
|
||||||
|
@ -74,11 +78,14 @@
|
||||||
<Version>1.0.1-beta-000933</Version>
|
<Version>1.0.1-beta-000933</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
|
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
|
||||||
<DefineConstants>$(DefineConstants);NETCOREAPP1_0</DefineConstants>
|
<DefineConstants>$(DefineConstants);NETCOREAPP1_0</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -2,9 +2,8 @@
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using Microsoft.DotNet.ProjectJsonMigration;
|
using Microsoft.DotNet.ProjectJsonMigration;
|
||||||
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
|
@ -13,7 +12,7 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
{
|
{
|
||||||
public static int NumberOfItemGroupsWithConditionContaining(this ProjectRootElement root, string patternInCondition)
|
public static int NumberOfItemGroupsWithConditionContaining(this ProjectRootElement root, string patternInCondition)
|
||||||
{
|
{
|
||||||
return root.ItemGroups.Count((ig) => ig.Condition.Contains(patternInCondition));
|
return root.ItemGroups.Count((itemGroup) => itemGroup.Condition.Contains(patternInCondition));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int NumberOfItemGroupsWithoutCondition(this ProjectRootElement root)
|
public static int NumberOfItemGroupsWithoutCondition(this ProjectRootElement root)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
||||||
using Xunit;
|
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
{
|
{
|
||||||
|
@ -20,19 +20,21 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "")
|
private TestSetup Setup([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(Setup), string identifier = "")
|
||||||
{
|
{
|
||||||
return new TestSetup(
|
return new TestSetup(
|
||||||
GetTestGroupTestAssetsManager(TestSetup.TestGroup)
|
TestAssets.Get(TestSetup.TestGroup, TestSetup.ProjectName)
|
||||||
.CreateTestInstance(TestSetup.ProjectName, callingMethod: callingMethod, identifier: identifier)
|
.CreateInstance()
|
||||||
.Path);
|
.WithSourceFiles()
|
||||||
|
.Root
|
||||||
|
.FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
||||||
{
|
{
|
||||||
return new ProjDir(TestAssetsManager, callingMethod, identifier: identifier);
|
return new ProjDir(TestAssetsManager.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjDir NewLib([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
private ProjDir NewLib([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
|
||||||
{
|
{
|
||||||
var dir = new ProjDir(TestAssetsManager, callingMethod, identifier: identifier);
|
var dir = NewDir(callingMethod: callingMethod, identifier: identifier);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -76,7 +78,6 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
||||||
public void WhenBrokenProjectIsPassedItPrintsErrorAndUsage()
|
public void WhenBrokenProjectIsPassedItPrintsErrorAndUsage()
|
||||||
{
|
{
|
||||||
string projName = "Broken/Broken.csproj";
|
string projName = "Broken/Broken.csproj";
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.DotNet.TestFramework;
|
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
using Microsoft.Build.Evaluation;
|
using Microsoft.Build.Evaluation;
|
||||||
|
|
||||||
|
@ -10,12 +9,6 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
{
|
{
|
||||||
internal class ProjDir
|
internal class ProjDir
|
||||||
{
|
{
|
||||||
public ProjDir(TestAssetsManager tam, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(ProjDir), string identifier = "")
|
|
||||||
{
|
|
||||||
Path = tam.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path;
|
|
||||||
Name = new DirectoryInfo(Path).Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProjDir(string path)
|
public ProjDir(string path)
|
||||||
{
|
{
|
||||||
Path = path;
|
Path = path;
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
using Microsoft.DotNet.TestFramework;
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue