fix some of the stuff in the feedback

This commit is contained in:
Krzysztof Wicher 2016-11-21 11:38:25 -08:00
parent 5d1deeeea1
commit 8e5ffaf176
19 changed files with 126 additions and 190 deletions

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,8 +1,3 @@
using System;
namespace SomeNS
public class SomeClass
{
public class SomeClass
{
}
}

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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" />
<PropertyGroup>
<OutputType>Library</OutputType>
@ -8,6 +7,8 @@
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<!-- This is intentionally empty - do not remove -->
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);NETCOREAPP1_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
<DefineConstants>$(DefineConstants);NET451</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -1,21 +0,0 @@
using NSLib1;
using NSLib3;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
#if NETCOREAPP1_0
Lib1.HelloNCA();
Lib3.HelloNCA();
#endif
#if NET451
Lib1.HelloNet451();
Lib3.HelloNet451();
#endif
}
}
}

View file

@ -1,24 +0,0 @@
using System;
using NSLib2;
namespace NSLib1
{
public class Lib1
{
#if NETCOREAPP1_0
public static void HelloNCA()
{
Console.WriteLine("Hello World from Lib1! (netcoreapp)");
Lib2.HelloNCA();
}
#endif
#if NET451
public static void HelloNet451()
{
Console.WriteLine("Hello World from Lib1! (net45)");
Lib2.HelloNet451();
}
#endif
}
}

View file

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);NETCOREAPP1_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
<DefineConstants>$(DefineConstants);NET451</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -1,21 +0,0 @@
using System;
namespace NSLib4
{
public class Lib4
{
#if NETCOREAPP1_0
public static void HelloNCA()
{
Console.WriteLine("Hello World from Lib4! (netcoreapp)");
}
#endif
#if NET451
public static void HelloNet451()
{
Console.WriteLine("Hello World from Lib4! (net45)");
}
#endif
}
}

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net451'">
<!-- Existing but empty item group for net451 - do not remove -->
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DefineConstants>$(DefineConstants);NETCOREAPP1_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
<DefineConstants>$(DefineConstants);NET451</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View file

@ -50,7 +50,10 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
throw new GracefulException("You must specify at least one reference to add.");
}
int numberOfAddedReferences = AddProjectToProjectReference(project, frameworkOption.Value(), app.RemainingArguments);
int numberOfAddedReferences = AddProjectToProjectReference(
project,
frameworkOption.Value(),
app.RemainingArguments);
if (numberOfAddedReferences != 0)
{
@ -74,7 +77,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
// There is ProjectRootElement.TryOpen but it does not work as expected
// I.e. it returns null for some valid projects
public static ProjectRootElement TryOpenProject(string filename)
internal static ProjectRootElement TryOpenProject(string filename)
{
try
{
@ -86,7 +89,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
}
}
public static ProjectRootElement GetProjectFromFileOrThrow(string filename)
internal static ProjectRootElement GetProjectFromFileOrThrow(string filename)
{
if (!File.Exists(filename))
{
@ -103,7 +106,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
}
// TODO: improve errors
public static ProjectRootElement GetProjectFromDirectoryOrThrow(string directory)
internal static ProjectRootElement GetProjectFromDirectoryOrThrow(string directory)
{
DirectoryInfo dir;
try
@ -128,7 +131,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
if (files.Length > 1)
{
throw new GracefulException("Found more than one MSBuild project in the current directory. Please specify which one to use.");
throw new GracefulException("Found more than one project in the current directory. Please specify which one to use.");
}
FileInfo projectFile = files.First();
@ -147,7 +150,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
return ret;
}
public static int AddProjectToProjectReference(ProjectRootElement root, string framework, IEnumerable<string> refs)
internal static int AddProjectToProjectReference(ProjectRootElement root, string framework, IEnumerable<string> refs)
{
int numberOfAddedReferences = 0;
const string ProjectItemElementType = "ProjectReference";

View file

@ -6,6 +6,7 @@ using System.IO;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using FluentAssertions;
using Microsoft.Build.Construction;
namespace Microsoft.DotNet.Cli.Add.P2P.Tests
{
@ -458,14 +459,99 @@ namespace Microsoft.DotNet.Cli.Add.P2P.Tests
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(LibRefPath, ConditionFrameworkNet451).Should().Be(1);
}
[Fact(Skip = "Not finished")]
[Fact]
public void WhenProjectNameIsNotPassedItFindsItAndAddsReference()
{
var lib = NewLib();
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddP2PCommand()
.WithWorkingDirectory(lib.Path)
.Execute($"\"{ValidRefPath}\"");
cmd.Should().Pass();
cmd.StdOut.Should().Contain("added to the project");
cmd.StdErr.Should().BeEmpty();
var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(ValidRefCsproj).Should().Be(1);
}
[Fact]
public void ItAddsRefBetweenImports()
{
var lib = NewLib();
var cmd = new AddP2PCommand()
.WithWorkingDirectory(lib.Path)
.WithProject(lib.CsProjName)
.Execute($"\"{ValidRefPath}\"");
cmd.Should().Pass();
cmd.StdOut.Should().Contain("added to the project");
cmd.StdErr.Should().BeEmpty();
int state = 0;
foreach (var el in lib.CsProj().AllChildren)
{
var import = el as ProjectImportElement;
var projRef = el as ProjectItemElement;
switch (state)
{
case 0:
if (import != null && import.Project.EndsWith(".props"))
{
state++;
}
break;
case 1:
if (projRef != null && projRef.ItemType == "ProjectReference" && projRef.Include.Contains(ValidRefCsproj))
{
state++;
}
break;
case 2:
if (import != null && import.Project.EndsWith(".targets"))
{
state++;
}
break;
}
}
state.Should().Be(3);
}
[Fact(Skip = "Not finished")]
public void WhenPassedReferenceDoesNotExistItShowsAnError()
{
throw new NotImplementedException();
}
[Fact(Skip = "Not finished")]
public void ItAddsRefBeforeImports()
public void WhenPassedMultipleRefsAndOneOfthemDoesNotExistItCancelsWholeOperation()
{
throw new NotImplementedException();
}
[Fact(Skip = "Not finished")]
public void WhenPassedReferenceDoesNotExistAndForceSwitchIsPassedItAddsIt()
{
throw new NotImplementedException();
}
[Fact(Skip = "Not finished")]
public void WhenPassedReferenceIsUsingSlashesItNormalizesItToBackslashes()
{
throw new NotImplementedException();
}
[Fact(Skip = "Not finished")]
public void WhenPassedRefIsUsingBackslashesItDoesntNormalizeIt()
{
throw new NotImplementedException();
}
[Fact(Skip = "Not finished")]
public void WhenReferenceIsRelativeAndProjectIsNotInCurrentDirectoryReferencePathIsFixed()
{
throw new NotImplementedException();
}