Merge branch 'rel/1.0.0' into patch-2

This commit is contained in:
Livar 2017-01-30 21:32:52 -08:00 committed by GitHub
commit 7efa9f082f
69 changed files with 446 additions and 197 deletions

View file

@ -1,20 +0,0 @@
{
"version": "1.0.0-*",
"namedResource": [ "My.Alias", "Strings.resx" ],
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
}
}

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;

View file

@ -0,0 +1,20 @@
{
"version": "1.0.0-*",
"namedResource": [ "My.Alias", "Strings.resx" ],
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
}
}

View file

@ -6,7 +6,7 @@
<CLI_NETSDK_Version>1.0.0-alpha-20170125-1</CLI_NETSDK_Version> <CLI_NETSDK_Version>1.0.0-alpha-20170125-1</CLI_NETSDK_Version>
<CLI_NuGet_Version>4.0.0-rtm-2241</CLI_NuGet_Version> <CLI_NuGet_Version>4.0.0-rtm-2241</CLI_NuGet_Version>
<CLI_WEBSDK_Version>1.0.0-alpha-20170120-3-249</CLI_WEBSDK_Version> <CLI_WEBSDK_Version>1.0.0-alpha-20170120-3-249</CLI_WEBSDK_Version>
<CLI_TestPlatform_Version>15.0.0-preview-20170123-02</CLI_TestPlatform_Version> <CLI_TestPlatform_Version>15.0.0-preview-20170125-04</CLI_TestPlatform_Version>
<TemplateEngineVersion>1.0.0-beta1-20170108-83</TemplateEngineVersion> <TemplateEngineVersion>1.0.0-beta1-20170108-83</TemplateEngineVersion>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View file

@ -4,10 +4,6 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public class CommandUnknownException : GracefulException public class CommandUnknownException : GracefulException
{ {
public CommandUnknownException()
{
}
public CommandUnknownException(string commandName) : base(string.Format( public CommandUnknownException(string commandName) : base(string.Format(
LocalizableStrings.NoExecutableFoundMatchingCommand, LocalizableStrings.NoExecutableFoundMatchingCommand,
commandName)) commandName))

View file

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.DotNet.Cli.Utils.ExceptionExtensions namespace Microsoft.DotNet.Cli.Utils
{ {
internal static class ExceptionExtensions internal static class ExceptionExtensions
{ {
@ -11,5 +11,10 @@ namespace Microsoft.DotNet.Cli.Utils.ExceptionExtensions
{ {
Reporter.Verbose.WriteLine($"Warning: Ignoring exception: {e.ToString().Yellow()}"); Reporter.Verbose.WriteLine($"Warning: Ignoring exception: {e.ToString().Yellow()}");
} }
public static bool ShouldBeDisplayedAsError(this Exception e) =>
e.Data.Contains(CLI_User_Displayed_Exception);
internal const string CLI_User_Displayed_Exception = "CLI_User_Displayed_Exception";
} }
} }

View file

@ -4,12 +4,9 @@ namespace Microsoft.DotNet.Cli.Utils
{ {
public class GracefulException : Exception public class GracefulException : Exception
{ {
public GracefulException()
{
}
public GracefulException(string message) : base(message) public GracefulException(string message) : base(message)
{ {
Data.Add(ExceptionExtensions.CLI_User_Displayed_Exception, true);
} }
public GracefulException(string format, params string[] args) : this(string.Format(format, args)) public GracefulException(string format, params string[] args) : this(string.Format(format, args))
@ -18,6 +15,7 @@ namespace Microsoft.DotNet.Cli.Utils
public GracefulException(string message, Exception innerException) : base(message, innerException) public GracefulException(string message, Exception innerException) : base(message, innerException)
{ {
Data.Add(ExceptionExtensions.CLI_User_Displayed_Exception, true);
} }
} }
} }

View file

@ -10,7 +10,6 @@ using Microsoft.DotNet.Internal.ProjectModel;
using Microsoft.DotNet.Internal.ProjectModel.Graph; using Microsoft.DotNet.Internal.ProjectModel.Graph;
using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli.Utils.ExceptionExtensions;
using Microsoft.DotNet.Cli.Sln.Internal; using Microsoft.DotNet.Cli.Sln.Internal;
using Microsoft.DotNet.ProjectJsonMigration.Rules; using Microsoft.DotNet.ProjectJsonMigration.Rules;
using Microsoft.DotNet.Tools.Common; using Microsoft.DotNet.Tools.Common;

View file

@ -43,7 +43,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
foreach (var item in msbuildProject.Items) foreach (var item in msbuildProject.Items)
{ {
if (string.IsNullOrEmpty(item.Include) && string.IsNullOrEmpty(item.Update)) if (string.IsNullOrEmpty(item.Include) &&
string.IsNullOrEmpty(item.Remove) &&
string.IsNullOrEmpty(item.Update))
{ {
item.Parent.RemoveChild(item); item.Parent.RemoveChild(item);
} }

View file

@ -55,7 +55,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
compilerOptions => compilerOptions.PreserveCompilationContext != null && compilerOptions.PreserveCompilationContext.Value); compilerOptions => compilerOptions.PreserveCompilationContext != null && compilerOptions.PreserveCompilationContext.Value);
private AddPropertyTransform<CommonCompilerOptions> WarningsAsErrorsTransform => private AddPropertyTransform<CommonCompilerOptions> WarningsAsErrorsTransform =>
new AddPropertyTransform<CommonCompilerOptions>("WarningsAsErrors", new AddPropertyTransform<CommonCompilerOptions>("TreatWarningsAsErrors",
compilerOptions => compilerOptions.WarningsAsErrors.ToString().ToLower(), compilerOptions => compilerOptions.WarningsAsErrors.ToString().ToLower(),
compilerOptions => compilerOptions.WarningsAsErrors != null && compilerOptions.WarningsAsErrors.Value); compilerOptions => compilerOptions.WarningsAsErrors != null && compilerOptions.WarningsAsErrors.Value);
@ -133,9 +133,17 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
condition: ic => ic != null, condition: ic => ic != null,
emitBuiltInIncludes: false); emitBuiltInIncludes: false);
private RemoveContextTransform RemoveCompileFilesTransform =>
new RemoveContextTransform(
"Compile",
condition: ic => ic != null);
private IncludeContextTransform EmbedFilesTransform => private IncludeContextTransform EmbedFilesTransform =>
new IncludeContextTransform("EmbeddedResource", transformMappings: false, condition: ic => ic != null); new IncludeContextTransform("EmbeddedResource", transformMappings: false, condition: ic => ic != null);
private RemoveContextTransform RemoveEmbedFilesTransform =>
new RemoveContextTransform("EmbeddedResource", condition: ic => ic != null);
private IncludeContextTransform CopyToOutputFilesTransform => private IncludeContextTransform CopyToOutputFilesTransform =>
new IncludeContextTransform("Content", transformMappings: true) new IncludeContextTransform("Content", transformMappings: true)
.WithMetadata("CopyToOutputDirectory", "PreserveNewest"); .WithMetadata("CopyToOutputDirectory", "PreserveNewest");
@ -157,14 +165,22 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
projectContext => string.Empty, projectContext => string.Empty,
projectContext => File.Exists(Path.Combine(projectContext.ProjectDirectory, "App.config"))); projectContext => File.Exists(Path.Combine(projectContext.ProjectDirectory, "App.config")));
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>CompileFilesTransformExecute => private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> CompileFilesTransformExecute =>
(compilerOptions, projectDirectory, projectType) => (compilerOptions, projectDirectory, projectType) =>
CompileFilesTransform.Transform(compilerOptions.CompileInclude); CompileFilesTransform.Transform(compilerOptions.CompileInclude);
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> RemoveCompileFilesTransformExecute =>
(compilerOptions, projectDirectory, projectType) =>
RemoveCompileFilesTransform.Transform(compilerOptions.CompileInclude);
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> EmbedFilesTransformExecute => private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> EmbedFilesTransformExecute =>
(compilerOptions, projectDirectory, projectType) => (compilerOptions, projectDirectory, projectType) =>
EmbedFilesTransform.Transform(GetEmbedIncludeContext(compilerOptions)); EmbedFilesTransform.Transform(GetEmbedIncludeContext(compilerOptions));
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> RemoveEmbedFilesTransformExecute =>
(compilerOptions, projectDirectory, projectType) =>
RemoveEmbedFilesTransform.Transform(GetEmbedIncludeContext(compilerOptions));
private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> CopyToOutputFilesTransformExecute => private Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>> CopyToOutputFilesTransformExecute =>
(compilerOptions, projectDirectory, projectType) => (compilerOptions, projectDirectory, projectType) =>
{ {
@ -183,6 +199,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
private readonly CommonCompilerOptions _configurationBuildOptions; private readonly CommonCompilerOptions _configurationBuildOptions;
private List<AddPropertyTransform<CommonCompilerOptions>> _propertyTransforms; private List<AddPropertyTransform<CommonCompilerOptions>> _propertyTransforms;
private List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>> _removeContextTransformExecutes;
private List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>> _includeContextTransformExecutes; private List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>> _includeContextTransformExecutes;
private readonly ITransformApplicator _transformApplicator; private readonly ITransformApplicator _transformApplicator;
@ -229,6 +246,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
_propertyTransforms.AddRange(EmitEntryPointTransforms); _propertyTransforms.AddRange(EmitEntryPointTransforms);
_propertyTransforms.AddRange(KeyFileTransforms); _propertyTransforms.AddRange(KeyFileTransforms);
_removeContextTransformExecutes =
new List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>>()
{
RemoveCompileFilesTransformExecute,
RemoveEmbedFilesTransformExecute
};
_includeContextTransformExecutes = _includeContextTransformExecutes =
new List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>>() new List<Func<CommonCompilerOptions, string, ProjectType, IEnumerable<ProjectItemElement>>>()
{ {
@ -311,6 +335,19 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
} }
} }
foreach (var removeContextTransformExecutes in _removeContextTransformExecutes)
{
var nonConfigurationOutput =
removeContextTransformExecutes(compilerOptions, projectDirectory, projectType);
var configurationOutput =
removeContextTransformExecutes(configurationCompilerOptions, projectDirectory, projectType);
if (configurationOutput != null)
{
transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: true);
}
}
foreach (var includeContextTransformExecute in _includeContextTransformExecutes) foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
{ {
var nonConfigurationOutput = var nonConfigurationOutput =
@ -318,7 +355,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var configurationOutput = var configurationOutput =
includeContextTransformExecute(configurationCompilerOptions, projectDirectory, projectType); includeContextTransformExecute(configurationCompilerOptions, projectDirectory, projectType);
if (configurationOutput != null) if (configurationOutput != null)
{ {
transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: true); transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: true);
@ -326,25 +362,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
} }
} }
private void RemoveCommonIncludes(IEnumerable<ProjectItemElement> itemsToRemoveFrom,
IEnumerable<ProjectItemElement> otherItems)
{
foreach (var item1 in itemsToRemoveFrom)
{
if (item1 == null)
{
continue;
}
foreach (
var item2 in
otherItems.Where(
i => i != null && string.Equals(i.ItemType, item1.ItemType, StringComparison.Ordinal)))
{
item1.Include = string.Join(";", item1.Includes().Except(item2.Includes()));
}
}
}
private bool PropertiesAreEqual(ProjectPropertyElement nonConfigurationOutput, ProjectPropertyElement configurationOutput) private bool PropertiesAreEqual(ProjectPropertyElement nonConfigurationOutput, ProjectPropertyElement configurationOutput)
{ {
if (configurationOutput != null && nonConfigurationOutput != null) if (configurationOutput != null && nonConfigurationOutput != null)
@ -369,6 +386,19 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
transformApplicator.Execute(transform.Transform(compilerOptions), propertyGroup, mergeExisting: true); transformApplicator.Execute(transform.Transform(compilerOptions), propertyGroup, mergeExisting: true);
} }
foreach (var removeContextTransformExecutes in _removeContextTransformExecutes)
{
var transform = removeContextTransformExecutes(compilerOptions, projectDirectory, projectType);
if (transform != null)
{
transformApplicator.Execute(
transform,
itemGroup,
mergeExisting: true);
}
}
foreach (var includeContextTransformExecute in _includeContextTransformExecutes) foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
{ {
var transform = includeContextTransformExecute(compilerOptions, projectDirectory, projectType); var transform = includeContextTransformExecute(compilerOptions, projectDirectory, projectType);

View file

@ -1,7 +1,11 @@
// 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 Microsoft.DotNet.Tools.Common;
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Microsoft.DotNet.ProjectJsonMigration.Transforms namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{ {
@ -25,5 +29,74 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
} }
public abstract U ConditionallyTransform(T source); public abstract U ConditionallyTransform(T source);
protected string FormatGlobPatternsForMsbuild(IEnumerable<string> patterns, string projectDirectory)
{
if (patterns == null)
{
return string.Empty;
}
List<string> mutatedPatterns = new List<string>(patterns.Count());
foreach (var pattern in patterns)
{
// Do not use forward slashes
// https://github.com/Microsoft/msbuild/issues/724
var mutatedPattern = pattern.Replace('/', '\\');
// MSBuild cannot copy directories
mutatedPattern = ReplaceDirectoriesWithGlobs(mutatedPattern, projectDirectory);
mutatedPatterns.Add(mutatedPattern);
}
return string.Join(";", mutatedPatterns);
}
private string ReplaceDirectoriesWithGlobs(string pattern, string projectDirectory)
{
if (PatternIsDirectory(pattern, projectDirectory))
{
return $"{pattern.TrimEnd(new char[] { '\\' })}\\**\\*";
}
else
{
return pattern;
}
}
private bool PatternIsDirectory(string pattern, string projectDirectory)
{
// TODO: what about /some/path/**/somedir?
// Should this even be migrated?
var path = pattern;
if (!Path.IsPathRooted(path))
{
path = Path.Combine(projectDirectory, path);
}
return Directory.Exists(path);
}
protected string ConvertTargetPathToMsbuildMetadata(string targetPath)
{
var targetIsFile = MappingsTargetPathIsFile(targetPath);
if (targetIsFile)
{
return targetPath;
}
return $"{targetPath}%(FileName)%(Extension)";
}
private bool MappingsTargetPathIsFile(string targetPath)
{
var normalizedTargetPath = PathUtility.GetPathWithDirectorySeparator(targetPath);
return normalizedTargetPath[normalizedTargetPath.Length - 1] != Path.DirectorySeparatorChar;
}
} }
} }

View file

@ -172,80 +172,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
return transformSet.Select(t => t.Item1.Transform(t.Item2)); return transformSet.Select(t => t.Item1.Transform(t.Item2));
} }
protected string FormatGlobPatternsForMsbuild(IEnumerable<string> patterns, string projectDirectory)
{
if (patterns == null)
{
return string.Empty;
}
List<string> mutatedPatterns = new List<string>(patterns.Count());
foreach (var pattern in patterns)
{
// Do not use forward slashes
// https://github.com/Microsoft/msbuild/issues/724
var mutatedPattern = pattern.Replace('/', '\\');
// MSBuild cannot copy directories
mutatedPattern = ReplaceDirectoriesWithGlobs(mutatedPattern, projectDirectory);
mutatedPatterns.Add(mutatedPattern);
}
return string.Join(";", mutatedPatterns);
}
private string ReplaceDirectoriesWithGlobs(string pattern, string projectDirectory)
{
if (PatternIsDirectory(pattern, projectDirectory))
{
return $"{pattern.TrimEnd(new char[] { '\\' })}\\**\\*";
}
else
{
return pattern;
}
}
private AddItemTransform<IncludeContext> AddMappingToTransform( private AddItemTransform<IncludeContext> AddMappingToTransform(
AddItemTransform<IncludeContext> addItemTransform, AddItemTransform<IncludeContext> addItemTransform,
string targetPath) string targetPath)
{ {
return _mappingsToTransfrom(addItemTransform, targetPath); return _mappingsToTransfrom(addItemTransform, targetPath);
} }
private bool PatternIsDirectory(string pattern, string projectDirectory)
{
// TODO: what about /some/path/**/somedir?
// Should this even be migrated?
var path = pattern;
if (!Path.IsPathRooted(path))
{
path = Path.Combine(projectDirectory, path);
}
return Directory.Exists(path);
}
private string ConvertTargetPathToMsbuildMetadata(string targetPath)
{
var targetIsFile = MappingsTargetPathIsFile(targetPath);
if (targetIsFile)
{
return targetPath;
}
return $"{targetPath}%(FileName)%(Extension)";
}
private bool MappingsTargetPathIsFile(string targetPath)
{
var normalizedTargetPath = PathUtility.GetPathWithDirectorySeparator(targetPath);
return normalizedTargetPath[normalizedTargetPath.Length - 1] != Path.DirectorySeparatorChar;
}
} }
} }

View file

@ -0,0 +1,110 @@
// 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 Microsoft.DotNet.Internal.ProjectModel.Files;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Construction;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectJsonMigration.Models;
using Microsoft.DotNet.Tools.Common;
namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{
internal class RemoveContextTransform : ConditionalTransform<IncludeContext, IEnumerable<ProjectItemElement>>
{
protected virtual Func<string, RemoveItemTransform<IncludeContext>> RemoveTransformGetter =>
(itemName) => new RemoveItemTransform<IncludeContext>(
itemName,
includeContext =>
{
var fullRemoveSet = includeContext.ExcludePatterns.OrEmptyIfNull()
.Union(includeContext.ExcludeFiles.OrEmptyIfNull());
return FormatGlobPatternsForMsbuild(fullRemoveSet, includeContext.SourceBasePath);
},
includeContext =>
{
return includeContext != null &&
(
(includeContext.ExcludePatterns != null && includeContext.ExcludePatterns.Count > 0)
||
(includeContext.ExcludeFiles != null && includeContext.ExcludeFiles.Count > 0)
);
});
private Func<string, string, RemoveItemTransform<IncludeContext>> MappingsRemoveTransformGetter =>
(itemName, targetPath) => AddMappingToTransform(RemoveTransformGetter(itemName), targetPath);
private Func<RemoveItemTransform<IncludeContext>, string, RemoveItemTransform<IncludeContext>> _mappingsToTransfrom;
private readonly string _itemName;
private readonly List<ItemMetadataValue<IncludeContext>> _metadata = new List<ItemMetadataValue<IncludeContext>>();
public RemoveContextTransform(
string itemName,
Func<IncludeContext, bool> condition = null
) : base(condition)
{
_itemName = itemName;
_mappingsToTransfrom = (removeItemTransform, targetPath) =>
{
var msbuildLinkMetadataValue = ConvertTargetPathToMsbuildMetadata(targetPath);
return removeItemTransform.WithMetadata("Link", msbuildLinkMetadataValue);
};
}
public override IEnumerable<ProjectItemElement> ConditionallyTransform(IncludeContext source)
{
var transformSet = CreateTransformSet(source);
return transformSet.Select(t => t.Item1.Transform(t.Item2));
}
private IEnumerable<Tuple<RemoveItemTransform<IncludeContext>, IncludeContext>> CreateTransformSet(IncludeContext source)
{
var transformSet = new List<Tuple<RemoveItemTransform<IncludeContext>, IncludeContext>>
{
Tuple.Create(RemoveTransformGetter(_itemName), source)
};
if (source == null)
{
return transformSet;
}
// Mappings must be executed before the transform set to prevent a the
// non-mapped items that will merge with mapped items from being encompassed
foreach (var mappingEntry in source.Mappings.OrEmptyIfNull())
{
var targetPath = mappingEntry.Key;
var includeContext = mappingEntry.Value;
transformSet.Insert(0,
Tuple.Create(
MappingsRemoveTransformGetter(_itemName, targetPath),
includeContext));
}
foreach (var metadataElement in _metadata)
{
foreach (var transform in transformSet)
{
transform.Item1.WithMetadata(metadataElement);
}
}
return transformSet;
}
private RemoveItemTransform<IncludeContext> AddMappingToTransform(
RemoveItemTransform<IncludeContext> removeItemTransform,
string targetPath)
{
return _mappingsToTransfrom(removeItemTransform, targetPath);
}
}
}

View file

@ -0,0 +1,69 @@
// 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;
using System.Collections.Generic;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration.Models;
namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
{
internal class RemoveItemTransform<T> : ConditionalTransform<T, ProjectItemElement>
{
private readonly ProjectRootElement _itemObjectGenerator = ProjectRootElement.Create();
private readonly string _itemName;
private readonly Func<T, string> _removeValueFunc;
private readonly List<ItemMetadataValue<T>> _metadata = new List<ItemMetadataValue<T>>();
public RemoveItemTransform(
string itemName,
Func<T, string> removeValueFunc,
Func<T, bool> condition)
: base(condition)
{
_itemName = itemName;
_removeValueFunc = removeValueFunc;
}
public RemoveItemTransform<T> WithMetadata(ItemMetadataValue<T> metadata)
{
_metadata.Add(metadata);
return this;
}
public RemoveItemTransform<T> WithMetadata(
string metadataName,
string metadataValue,
bool expressedAsAttribute = false)
{
_metadata.Add(new ItemMetadataValue<T>(
metadataName,
metadataValue,
expressedAsAttribute: expressedAsAttribute));
return this;
}
public override ProjectItemElement ConditionallyTransform(T source)
{
string removeValue = _removeValueFunc(source);
var item = _itemObjectGenerator.AddItem(_itemName, "PlaceHolderSinceNullOrEmptyCannotBePassedToConstructor");
item.Include = null;
item.Remove = removeValue;
foreach (var metadata in _metadata)
{
if (metadata.ShouldWriteMetadata(source))
{
var metametadata = item.AddMetadata(metadata.MetadataName, metadata.GetMetadataValue(source));
metametadata.Condition = metadata.Condition;
metametadata.ExpressedAsAttribute = metadata.ExpressedAsAttribute;
}
}
return item;
}
}
}

View file

@ -2,6 +2,7 @@
// 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;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools; using Microsoft.DotNet.Tools;
namespace Microsoft.DotNet.Cli.CommandLine namespace Microsoft.DotNet.Cli.CommandLine
@ -18,6 +19,8 @@ namespace Microsoft.DotNet.Cli.CommandLine
{ {
Command = command; Command = command;
_isRequireSubCommandMissing = isRequireSubCommandMissing; _isRequireSubCommandMissing = isRequireSubCommandMissing;
Data.Add("CLI_User_Displayed_Exception", true);
} }
public CommandLineApplication Command { get; } public CommandLineApplication Command { get; }

View file

@ -4,7 +4,6 @@
using System; using System;
using System.Runtime.Loader; using System.Runtime.Loader;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli.Utils.ExceptionExtensions;
using Microsoft.DotNet.Tools.Common; using Microsoft.DotNet.Tools.Common;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Configurer; using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.PlatformAbstractions; using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.Tools.Add; using Microsoft.DotNet.Tools.Add;
@ -76,9 +77,11 @@ namespace Microsoft.DotNet.Cli
return ProcessArgs(args); return ProcessArgs(args);
} }
} }
catch (GracefulException e) catch (Exception e) when (e.ShouldBeDisplayedAsError())
{ {
Reporter.Error.WriteLine(CommandContext.IsVerbose() ? e.ToString().Red().Bold() : e.Message.Red().Bold()); Reporter.Error.WriteLine(CommandContext.IsVerbose() ?
e.ToString().Red().Bold() :
e.Message.Red().Bold());
return 1; return 1;
} }

View file

@ -29,7 +29,7 @@ namespace Microsoft.DotNet.Tools.Build
CommandOption runtimeOption = app.Option( CommandOption runtimeOption = app.Option(
$"-r|--runtime <{LocalizableStrings.RuntimeOptionName}>", LocalizableStrings.RuntimeOptionDescription, $"-r|--runtime <{LocalizableStrings.RuntimeOptionName}>", LocalizableStrings.RuntimeOptionDescription,
CommandOptionType.SingleValue); CommandOptionType.SingleValue);
CommandOption configurationOption = app.Option($"-c|--configuration <{LocalizableStrings.ConfigurationOptionName}>", LocalizableStrings.FrameworkOptionDescription, CommandOptionType.SingleValue); CommandOption configurationOption = app.Option($"-c|--configuration <{LocalizableStrings.ConfigurationOptionName}>", LocalizableStrings.ConfigurationOptionDescription, CommandOptionType.SingleValue);
CommandOption versionSuffixOption = app.Option($"--version-suffix <{LocalizableStrings.VersionSuffixOptionName}>", LocalizableStrings.VersionSuffixOptionDescription, CommandOptionType.SingleValue); CommandOption versionSuffixOption = app.Option($"--version-suffix <{LocalizableStrings.VersionSuffixOptionName}>", LocalizableStrings.VersionSuffixOptionDescription, CommandOptionType.SingleValue);
CommandOption noIncrementalOption = app.Option("--no-incremental", LocalizableStrings.NoIncrementialOptionDescription, CommandOptionType.NoValue); CommandOption noIncrementalOption = app.Option("--no-incremental", LocalizableStrings.NoIncrementialOptionDescription, CommandOptionType.NoValue);

View file

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170123-02" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170125-04" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.10-rc2" /> <PackageReference Include="MSTest.TestAdapter" Version="1.1.10-rc2" />
<PackageReference Include="MSTest.TestFramework" Version="1.0.8-rc2" /> <PackageReference Include="MSTest.TestFramework" Version="1.0.8-rc2" />
</ItemGroup> </ItemGroup>

View file

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170123-02" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170125-04" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" /> <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
</ItemGroup> </ItemGroup>

View file

@ -13,7 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.0-beta-*" PrivateAssets="All"/> <PackageReference Include="FSharp.NET.Sdk" Version="1.0.0-beta-*" PrivateAssets="All"/>
<PackageReference Include="Microsoft.FSharp.Core.netcore" Version="1.0.0-alpha-161023" /> <PackageReference Include="Microsoft.FSharp.Core.netcore" Version="1.0.0-alpha-161023" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170123-02" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170125-04" />
<PackageReference Include="MSTest.TestAdapter" Version="1.1.10-rc2" /> <PackageReference Include="MSTest.TestAdapter" Version="1.1.10-rc2" />
<PackageReference Include="MSTest.TestFramework" Version="1.0.8-rc2" /> <PackageReference Include="MSTest.TestFramework" Version="1.0.8-rc2" />
</ItemGroup> </ItemGroup>

View file

@ -13,7 +13,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.0-beta-*" PrivateAssets="All" /> <PackageReference Include="FSharp.NET.Sdk" Version="1.0.0-beta-*" PrivateAssets="All" />
<PackageReference Include="Microsoft.FSharp.Core.netcore" Version="1.0.0-alpha-161023" /> <PackageReference Include="Microsoft.FSharp.Core.netcore" Version="1.0.0-alpha-161023" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170123-02" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170125-04" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" /> <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
</ItemGroup> </ItemGroup>

View file

@ -43,7 +43,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void ItHasWarningWhenMigratingADeprecatedProjectJson() public void ItHasWarningWhenMigratingADeprecatedProjectJson()
{ {
var testProjectDirectory = TestAssets var testProjectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompileOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompile")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -69,7 +69,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void ItHasErrorWhenMigratingADeprecatedNamedResourceOptionProjectJson() public void ItHasErrorWhenMigratingADeprecatedNamedResourceOptionProjectJson()
{ {
var testProjectDirectory = TestAssets var testProjectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedNamedResourceOption") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedNamedResource")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root

View file

@ -193,8 +193,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
}"); }");
mockProj.Properties.Count(p => p.Name == "WarningsAsErrors").Should().Be(1); mockProj.Properties.Count(p => p.Name == "TreatWarningsAsErrors").Should().Be(1);
mockProj.Properties.First(p => p.Name == "WarningsAsErrors").Value.Should().Be("true"); mockProj.Properties.First(p => p.Name == "TreatWarningsAsErrors").Value.Should().Be("true");
mockProj = RunBuildOptionsRuleOnPj(@" mockProj = RunBuildOptionsRuleOnPj(@"
{ {
@ -203,7 +203,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
}"); }");
mockProj.Properties.Count(p => p.Name == "WarningsAsErrors").Should().Be(0); mockProj.Properties.Count(p => p.Name == "TreatWarningsAsErrors").Should().Be(0);
} }
[Fact] [Fact]
@ -420,12 +420,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
[Theory] [Theory]
[InlineData("compile", "Compile", "")] [InlineData("compile", "Compile", 3, "")]
[InlineData("embed", "EmbeddedResource", ";rootfile.cs")] [InlineData("embed", "EmbeddedResource", 3, ";rootfile.cs")]
[InlineData("copyToOutput", "Content", ";rootfile.cs")] [InlineData("copyToOutput", "Content", 2, ";rootfile.cs")]
private void MigratingGroupIncludeExcludePopulatesAppropriateProjectItemElement( private void MigratingGroupIncludeExcludePopulatesAppropriateProjectItemElement(
string group, string group,
string itemName, string itemName,
int expectedNumberOfCompileItems,
string expectedRootFiles) string expectedRootFiles)
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
@ -446,7 +447,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
var mockProj = RunBuildOptionsRuleOnPj(pj, var mockProj = RunBuildOptionsRuleOnPj(pj,
testDirectory: testDirectory); testDirectory: testDirectory);
mockProj.Items.Count(i => i.ItemType.Equals(itemName, StringComparison.Ordinal)).Should().Be(2); mockProj.Items.Count(i => i.ItemType.Equals(itemName, StringComparison.Ordinal))
.Should().Be(expectedNumberOfCompileItems);
var defaultIncludePatterns = GetDefaultIncludePatterns(group); var defaultIncludePatterns = GetDefaultIncludePatterns(group);
var defaultExcludePatterns = GetDefaultExcludePatterns(group); var defaultExcludePatterns = GetDefaultExcludePatterns(group);
@ -455,7 +457,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
{ {
VerifyContentMetadata(item); VerifyContentMetadata(item);
if (item.Include.Contains(@"src\file1.cs")) if (string.IsNullOrEmpty(item.Include))
{
item.Remove.Should()
.Be(@"src\**\*;rootfile.cs;src\file2.cs");
}
else if (item.Include.Contains(@"src\file1.cs"))
{ {
item.Include.Should().Be(@"src\file1.cs;src\file2.cs"); item.Include.Should().Be(@"src\file1.cs;src\file2.cs");
item.Exclude.Should().Be(@"src\file2.cs"); item.Exclude.Should().Be(@"src\file2.cs");

View file

@ -15,10 +15,10 @@ namespace Microsoft.DotNet.Migration.Tests
public class GivenThatIWantToMigrateDeprecatedProjects : TestBase public class GivenThatIWantToMigrateDeprecatedProjects : TestBase
{ {
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedPackOptionsWarningsArePrinted() public void WhenMigratingDeprecatedPackOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedPackOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedPack")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -52,10 +52,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedPackOptionsItSucceeds() public void MigrateDeprecatedPack()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedPackOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedPack")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -82,17 +82,17 @@ namespace Microsoft.DotNet.Migration.Tests
var outputDir = projectDirectory.GetDirectory("bin", "Debug"); var outputDir = projectDirectory.GetDirectory("bin", "Debug");
outputDir.Should().Exist() outputDir.Should().Exist()
.And.HaveFile("PJAppWithDeprecatedPackOptions.1.0.0.nupkg"); .And.HaveFile("PJDeprecatedPack.1.0.0.nupkg");
var outputPackage = outputDir.GetFile("PJAppWithDeprecatedPackOptions.1.0.0.nupkg"); var outputPackage = outputDir.GetFile("PJDeprecatedPack.1.0.0.nupkg");
var zip = ZipFile.Open(outputPackage.FullName, ZipArchiveMode.Read); var zip = ZipFile.Open(outputPackage.FullName, ZipArchiveMode.Read);
zip.Entries.Should().Contain(e => e.FullName == "PJAppWithDeprecatedPackOptions.nuspec") zip.Entries.Should().Contain(e => e.FullName == "PJDeprecatedPack.nuspec")
.And.Contain(e => e.FullName == "content/Content1.txt") .And.Contain(e => e.FullName == "content/Content1.txt")
.And.Contain(e => e.FullName == "content/Content2.txt"); .And.Contain(e => e.FullName == "content/Content2.txt");
var manifestReader = new StreamReader( var manifestReader = new StreamReader(
zip.Entries.First(e => e.FullName == "PJAppWithDeprecatedPackOptions.nuspec").Open()); zip.Entries.First(e => e.FullName == "PJDeprecatedPack.nuspec").Open());
// NOTE: Commented out those that are not migrated. // NOTE: Commented out those that are not migrated.
// https://microsoft.sharepoint.com/teams/netfx/corefx/_layouts/15/WopiFrame.aspx?sourcedoc=%7B0cfbc196-0645-4781-84c6-5dffabd76bee%7D&action=edit&wd=target%28Planning%2FMSBuild%20CLI%20integration%2Eone%7C41D470DD-CF44-4595-8E05-0CE238864B55%2FProject%2Ejson%20Migration%7CA553D979-EBC6-484B-A12E-036E0730864A%2F%29 // https://microsoft.sharepoint.com/teams/netfx/corefx/_layouts/15/WopiFrame.aspx?sourcedoc=%7B0cfbc196-0645-4781-84c6-5dffabd76bee%7D&action=edit&wd=target%28Planning%2FMSBuild%20CLI%20integration%2Eone%7C41D470DD-CF44-4595-8E05-0CE238864B55%2FProject%2Ejson%20Migration%7CA553D979-EBC6-484B-A12E-036E0730864A%2F%29
@ -120,10 +120,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompilationOptionsWarningsArePrinted() public void WhenMigratingDeprecatedCompilationOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompilationOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompilation")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -141,10 +141,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompilationOptionsItSucceeds() public void MigratingDeprecatedCompilation()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompilationOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompilation")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -166,10 +166,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedContentOptionsWarningsArePrinted() public void WhenMigratingDeprecatedContentOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedContentOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedContent")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -191,10 +191,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedContentOptionsItSucceeds() public void MigratingDeprecatedContent()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedContentOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedContent")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -248,10 +248,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompileOptionsWarningsArePrinted() public void WhenMigratingDeprecatedCompileOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompileOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompile")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -269,10 +269,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompileOptionsItSucceeds() public void MigratingDeprecatedCompile()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompileOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompile")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -295,10 +295,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompileBuiltInOptionsWarningsArePrinted() public void WhenMigratingDeprecatedCompileBuiltInOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompileBuiltInOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompileBuiltIn")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -314,10 +314,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompileBuiltInOptionsItSucceeds() public void MigratingDeprecatedCompileBuiltIn()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompileBuiltInOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompileBuiltIn")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -341,10 +341,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompileExcludeOptionsWarningsArePrinted() public void WhenMigratingDeprecatedCompileExcludeOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompileExcludeOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompileExclude")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -360,10 +360,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedCompileExcludeOptionsItSucceeds() public void MigratingDeprecatedCompileExclude()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedCompileExcludeOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompileExclude")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -378,18 +378,17 @@ namespace Microsoft.DotNet.Migration.Tests
.Execute("restore") .Execute("restore")
.Should().Pass(); .Should().Pass();
// Issue: https://github.com/dotnet/cli/issues/5461 new DotnetCommand()
//new DotnetCommand() .WithWorkingDirectory(projectDirectory)
// .WithWorkingDirectory(projectDirectory) .Execute("build -c Debug")
// .Execute("build -c Debug") .Should().Pass();
// .Should().Pass();
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedResourceOptionsWarningsArePrinted() public void WhenMigratingDeprecatedResourceOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedResource")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -408,10 +407,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedResourceOptionsItSucceeds() public void MigratingDeprecatedResource()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedResource")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -440,10 +439,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedResourceBuiltInOptionsWarningsArePrinted() public void WhenMigratingDeprecatedResourceBuiltInOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceBuiltInOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedResourceBuiltIn")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -460,10 +459,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingDeprecatedBuiltInResItSucceeds() public void MigratingDeprecatedResourceBuiltIn()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceBuiltInOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedResourceBuiltIn")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root .Root
@ -493,10 +492,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedResourceExcludeOptionsWarningsArePrinted() public void WhenMigratingDeprecatedResourceExcludeOptionsWarningsArePrinted()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceExcludeOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedResourceExclude")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -512,10 +511,10 @@ namespace Microsoft.DotNet.Migration.Tests
} }
[Fact] [Fact]
public void WhenMigratingAProjectWithDeprecatedResourceExcludeOptionsItSucceeds() public void MigratingDeprecatedResourceExclude()
{ {
var projectDirectory = TestAssets var projectDirectory = TestAssets
.GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJAppWithDeprecatedResourceExcludeOptions") .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedResourceExclude")
.CreateInstance() .CreateInstance()
.WithSourceFiles() .WithSourceFiles()
.Root; .Root;
@ -530,17 +529,16 @@ namespace Microsoft.DotNet.Migration.Tests
.Execute("restore") .Execute("restore")
.Should().Pass(); .Should().Pass();
// Issue: https://github.com/dotnet/cli/issues/5461 new DotnetCommand()
//new DotnetCommand() .WithWorkingDirectory(projectDirectory)
// .WithWorkingDirectory(projectDirectory) .Execute("build -c Debug")
// .Execute("build -c Debug") .Should().Pass();
// .Should().Pass();
//var cmd = new DotnetCommand() var cmd = new DotnetCommand()
// .WithWorkingDirectory(projectDirectory) .WithWorkingDirectory(projectDirectory)
// .ExecuteWithCapturedOutput("run -c Debug"); .ExecuteWithCapturedOutput("run -c Debug");
//cmd.Should().Pass(); cmd.Should().Pass();
//cmd.StdOut.Should().Contain("0 Resources Found:"); cmd.StdOut.Should().Contain("0 Resources Found:");
} }
} }
} }

View file

@ -0,0 +1,26 @@
// 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 FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using System;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
namespace Microsoft.DotNet.New.Tests
{
public class NewCommandTests
{
[Fact]
public void WhenSwitchIsSkippedThenItPrintsError()
{
var cmd = new DotnetCommand().Execute("new Web1.1");
cmd.ExitCode.Should().NotBe(0);
cmd.StdErr.Should().Be("Unrecognized command or argument 'Web1.1'");
cmd.StdOut.Should().Be("Specify --help for a list of available options and commands.");
}
}
}