From c8a6b7b97a7487d7d942e251ca43ad068ae9ec58 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Tue, 18 Apr 2017 18:39:15 -0700 Subject: [PATCH 01/17] Add .binlog (MSBuild binary log format) extension to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3fc22dc00..7bed92752 100644 --- a/.gitignore +++ b/.gitignore @@ -115,6 +115,7 @@ artifacts/ *.tmp *.tmp_proj *.log +*.binlog *.vspscc *.vssscc .builds From fa51bb43fc861f9d4ba7b8fca199dc96edcfd299 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Tue, 18 Apr 2017 18:48:53 -0700 Subject: [PATCH 02/17] Call into project in .NET SDK to create deps.json files for tools instead of doing so directly --- .../IPackagedCommandSpecFactory.cs | 12 +- .../CommandResolution/IProject.cs | 2 + .../CommandResolution/MSBuildProject.cs | 13 +++ .../PackagedCommandSpecFactory.cs | 36 +----- .../ProjectDependenciesCommandResolver.cs | 4 +- .../ProjectToolsCommandResolver.cs | 70 +++++++++--- .../Extensions/LockFileExtensions.cs | 33 ++++++ .../ForwardingAppImplementation.cs | 108 ++++++++++++++++++ .../MSBuildForwardingAppWithoutLogging.cs | 84 ++++++++++++++ .../ProcessStartInfoExtensions.cs | 2 +- src/dotnet/ForwardingApp.cs | 92 +++------------ src/dotnet/NuGetForwardingApp.cs | 1 + .../dotnet-msbuild/MSBuildForwardingApp.cs | 75 +++--------- 13 files changed, 337 insertions(+), 195 deletions(-) create mode 100644 src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs create mode 100644 src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs create mode 100644 src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs rename src/{dotnet => Microsoft.DotNet.Cli.Utils}/ProcessStartInfoExtensions.cs (95%) diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs index 20f8a3302..15ed9fde5 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs @@ -8,22 +8,14 @@ namespace Microsoft.DotNet.Cli.Utils { public interface IPackagedCommandSpecFactory { - CommandSpec CreateCommandSpecFromLibrary( - LockFileTargetLibrary toolLibrary, - string commandName, - IEnumerable commandArguments, - IEnumerable allowedExtensions, - string nugetPackagesRoot, - CommandResolutionStrategy commandResolutionStrategy, - string depsFilePath, - string runtimeConfigPath); + // Code review TODO: Is it OK to make breaking changes to the CLI Utils API surface? CommandSpec CreateCommandSpecFromLibrary( LockFileTargetLibrary toolLibrary, string commandName, IEnumerable commandArguments, IEnumerable allowedExtensions, - IEnumerable packageFolders, + LockFile lockFile, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath, string runtimeConfigPath); diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IProject.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IProject.cs index 9a97bb1e5..534d77ebe 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IProject.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IProject.cs @@ -26,5 +26,7 @@ namespace Microsoft.DotNet.Cli.Utils NuGetFramework DotnetCliToolTargetFramework { get; } Dictionary EnvironmentVariables { get; } + + string ToolDepsJsonGeneratorProject { get; } } } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/MSBuildProject.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/MSBuildProject.cs index cb006e4a5..f5473c278 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/MSBuildProject.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/MSBuildProject.cs @@ -92,6 +92,19 @@ namespace Microsoft.DotNet.Cli.Utils } } + public string ToolDepsJsonGeneratorProject + { + get + { + var generatorProject = _project + .AllEvaluatedProperties + .FirstOrDefault(p => p.Name.Equals("ToolDepsJsonGeneratorProject")) + ?.EvaluatedValue; + + return generatorProject; + } + } + public MSBuildProject( string msBuildProjectPath, NuGetFramework framework, diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs index e7bd1b33c..2ee8bcb6a 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs @@ -27,28 +27,7 @@ namespace Microsoft.DotNet.Cli.Utils string commandName, IEnumerable commandArguments, IEnumerable allowedExtensions, - string nugetPackagesRoot, - CommandResolutionStrategy commandResolutionStrategy, - string depsFilePath, - string runtimeConfigPath) - { - return CreateCommandSpecFromLibrary( - toolLibrary, - commandName, - commandArguments, - allowedExtensions, - new List { nugetPackagesRoot }, - commandResolutionStrategy, - depsFilePath, - runtimeConfigPath); - } - - public CommandSpec CreateCommandSpecFromLibrary( - LockFileTargetLibrary toolLibrary, - string commandName, - IEnumerable commandArguments, - IEnumerable allowedExtensions, - IEnumerable packageFolders, + LockFile lockFile, CommandResolutionStrategy commandResolutionStrategy, string depsFilePath, string runtimeConfigPath) @@ -72,7 +51,7 @@ namespace Microsoft.DotNet.Cli.Utils return null; } - var commandPath = GetCommandFilePath(packageFolders, toolLibrary, toolAssembly); + var commandPath = GetCommandFilePath(lockFile, toolLibrary, toolAssembly); if (!File.Exists(commandPath)) { @@ -89,21 +68,16 @@ namespace Microsoft.DotNet.Cli.Utils commandArguments, depsFilePath, commandResolutionStrategy, - packageFolders, + lockFile.GetNormalizedPackageFolders(), runtimeConfigPath); } private string GetCommandFilePath( - IEnumerable packageFolders, + LockFile lockFile, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly) { - var packageFoldersCount = packageFolders.Count(); - var userPackageFolder = packageFoldersCount == 1 ? string.Empty : packageFolders.First(); - var fallbackPackageFolders = packageFoldersCount > 1 ? packageFolders.Skip(1) : packageFolders; - - var packageDirectory = new FallbackPackagePathResolver(userPackageFolder, fallbackPackageFolders) - .GetPackageDirectory(toolLibrary.Name, toolLibrary.Version); + var packageDirectory = lockFile.GetPackageDirectory(toolLibrary); if (packageDirectory == null) { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs index 9c1e97e5b..557ca3b25 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs @@ -120,15 +120,13 @@ namespace Microsoft.DotNet.Cli.Utils var lockFile = project.GetLockFile(); var toolLibrary = GetToolLibraryForContext(lockFile, commandName, framework); - var normalizedNugetPackagesRoot = - PathUtility.EnsureNoTrailingDirectorySeparator(lockFile.PackageFolders.First().Path); var commandSpec = _packagedCommandSpecFactory.CreateCommandSpecFromLibrary( toolLibrary, commandName, commandArguments, allowedExtensions, - normalizedNugetPackagesRoot, + lockFile, s_commandResolutionStrategy, depsFilePath, runtimeConfigPath); diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs index 85f82bcd2..d95cfead2 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs @@ -170,10 +170,8 @@ namespace Microsoft.DotNet.Cli.Utils toolLibraryRange, toolPackageFramework, toolLockFile, - depsFileRoot); - - var packageFolders = toolLockFile.PackageFolders.Select(p => - PathUtility.EnsureNoTrailingDirectorySeparator(p.Path)); + depsFileRoot, + project.ToolDepsJsonGeneratorProject); Reporter.Verbose.WriteLine(string.Format( LocalizableStrings.AttemptingToCreateCommandSpec, @@ -184,7 +182,7 @@ namespace Microsoft.DotNet.Cli.Utils commandName, args, _allowedCommandExtensions, - packageFolders, + toolLockFile, s_commandResolutionStrategy, depsFilePath, null); @@ -281,7 +279,8 @@ namespace Microsoft.DotNet.Cli.Utils SingleProjectInfo toolLibrary, NuGetFramework framework, LockFile toolLockFile, - string depsPathRoot) + string depsPathRoot, + string toolDepsJsonGeneratorProject) { var depsJsonPath = Path.Combine( depsPathRoot, @@ -292,7 +291,7 @@ namespace Microsoft.DotNet.Cli.Utils ProjectToolsCommandResolverName, depsJsonPath)); - EnsureToolJsonDepsFileExists(toolLockFile, framework, depsJsonPath, toolLibrary); + EnsureToolJsonDepsFileExists(toolLockFile, framework, depsJsonPath, toolLibrary, toolDepsJsonGeneratorProject); return depsJsonPath; } @@ -301,11 +300,12 @@ namespace Microsoft.DotNet.Cli.Utils LockFile toolLockFile, NuGetFramework framework, string depsPath, - SingleProjectInfo toolLibrary) + SingleProjectInfo toolLibrary, + string toolDepsJsonGeneratorProject) { if (!File.Exists(depsPath)) { - GenerateDepsJsonFile(toolLockFile, framework, depsPath, toolLibrary); + GenerateDepsJsonFile(toolLockFile, framework, depsPath, toolLibrary, toolDepsJsonGeneratorProject); } } @@ -313,7 +313,8 @@ namespace Microsoft.DotNet.Cli.Utils LockFile toolLockFile, NuGetFramework framework, string depsPath, - SingleProjectInfo toolLibrary) + SingleProjectInfo toolLibrary, + string toolDepsJsonGeneratorProject) { Reporter.Verbose.WriteLine(string.Format( LocalizableStrings.GeneratingDepsJson, @@ -323,11 +324,52 @@ namespace Microsoft.DotNet.Cli.Utils .Build(toolLibrary, null, toolLockFile, framework, null); var tempDepsFile = Path.GetTempFileName(); - using (var fileStream = File.Open(tempDepsFile, FileMode.Open, FileAccess.Write)) - { - var dependencyContextWriter = new DependencyContextWriter(); - dependencyContextWriter.Write(dependencyContext, fileStream); + var args = new List(); + + args.Add(toolDepsJsonGeneratorProject); + args.Add($"/p:ProjectAssetsFile=\"{toolLockFile.Path}\""); + args.Add($"/p:ToolName={toolLibrary.Name}"); + args.Add($"/p:ProjectDepsFilePath={tempDepsFile}"); + + + // Look for the .props file in the Microsoft.NETCore.App package, until NuGet + // generates .props and .targets files for tool restores (https://github.com/NuGet/Home/issues/5037) + var platformLibrary = toolLockFile.Targets + .FirstOrDefault(t => framework == t.TargetFramework) + ?.GetPlatformLibrary(); + + if (platformLibrary != null) + { + string buildRelativePath = platformLibrary.Build.FirstOrDefault()?.Path; + + var platformLibraryPath = toolLockFile.GetPackageDirectory(platformLibrary); + + if (platformLibraryPath != null && buildRelativePath != null) + { + // Get rid of "_._" filename + buildRelativePath = Path.GetDirectoryName(buildRelativePath); + + string platformLibraryBuildFolderPath = Path.Combine(platformLibraryPath, buildRelativePath); + var platformLibraryPropsFile = Directory.GetFiles(platformLibraryBuildFolderPath, "*.props").FirstOrDefault(); + + if (platformLibraryPropsFile != null) + { + args.Add($"/p:AdditionalImport={platformLibraryPropsFile}"); + } + } + } + + // Delete temporary file created by Path.GetTempFileName(), otherwise the GenerateBuildDependencyFile target + // will think the deps file is up-to-date and skip executing + File.Delete(tempDepsFile); + + var result = new MSBuildForwardingAppWithoutLogging(args).Execute(); + + if (result != 0) + { + // TODO: Can / should we show the MSBuild output if there is a failure? + throw new GracefulException(string.Format(LocalizableStrings.UnableToGenerateDepsJson, toolDepsJsonGeneratorProject)); } try diff --git a/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs b/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs new file mode 100644 index 000000000..5b504badf --- /dev/null +++ b/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs @@ -0,0 +1,33 @@ +using Microsoft.DotNet.Tools.Common; +using NuGet.Packaging; +using NuGet.ProjectModel; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Microsoft.DotNet.Cli.Utils +{ + static class LockFileExtensions + { + public static string GetPackageDirectory(this LockFile lockFile, LockFileTargetLibrary library) + { + var packageFolders = lockFile.GetNormalizedPackageFolders(); + + var packageFoldersCount = packageFolders.Count(); + var userPackageFolder = packageFoldersCount == 1 ? string.Empty : packageFolders.First(); + var fallbackPackageFolders = packageFoldersCount > 1 ? packageFolders.Skip(1) : packageFolders; + + var packageDirectory = new FallbackPackagePathResolver(userPackageFolder, fallbackPackageFolders) + .GetPackageDirectory(library.Name, library.Version); + + return packageDirectory; + } + + public static IEnumerable GetNormalizedPackageFolders(this LockFile lockFile) + { + return lockFile.PackageFolders.Select(p => + PathUtility.EnsureNoTrailingDirectorySeparator(p.Path)); + } + } +} diff --git a/src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs b/src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs new file mode 100644 index 000000000..cb5098bc0 --- /dev/null +++ b/src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs @@ -0,0 +1,108 @@ +// 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.Collections.Generic; +using System.Diagnostics; +using Microsoft.DotNet.Cli.Utils; + +namespace Microsoft.DotNet.Cli.Utils +{ + /// + /// A class which encapsulates logic needed to forward arguments from the current process to another process + /// invoked with the dotnet.exe host. + /// + internal class ForwardingAppImplementation + { + private const string s_hostExe = "dotnet"; + + private readonly string _forwardApplicationPath; + private readonly IEnumerable _argsToForward; + private readonly string _depsFile; + private readonly string _runtimeConfig; + private readonly string _additionalProbingPath; + private Dictionary _environmentVariables; + + private readonly string[] _allArgs; + + public ForwardingAppImplementation( + string forwardApplicationPath, + IEnumerable argsToForward, + string depsFile = null, + string runtimeConfig = null, + string additionalProbingPath = null, + Dictionary environmentVariables = null) + { + _forwardApplicationPath = forwardApplicationPath; + _argsToForward = argsToForward; + _depsFile = depsFile; + _runtimeConfig = runtimeConfig; + _additionalProbingPath = additionalProbingPath; + _environmentVariables = environmentVariables; + + var allArgs = new List(); + allArgs.Add("exec"); + + if (_depsFile != null) + { + allArgs.Add("--depsfile"); + allArgs.Add(_depsFile); + } + + if (_runtimeConfig != null) + { + allArgs.Add("--runtimeconfig"); + allArgs.Add(_runtimeConfig); + } + + if (_additionalProbingPath != null) + { + allArgs.Add("--additionalprobingpath"); + allArgs.Add(_additionalProbingPath); + } + + allArgs.Add(_forwardApplicationPath); + allArgs.AddRange(_argsToForward); + + _allArgs = allArgs.ToArray(); + } + + public int Execute() + { + return GetProcessStartInfo().Execute(); + } + + public ProcessStartInfo GetProcessStartInfo() + { + var processInfo = new ProcessStartInfo + { + FileName = GetHostExeName(), + Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(_allArgs), + UseShellExecute = false + }; + + if (_environmentVariables != null) + { + foreach (var entry in _environmentVariables) + { + processInfo.Environment[entry.Key] = entry.Value; + } + } + + return processInfo; + } + + public ForwardingAppImplementation WithEnvironmentVariable(string name, string value) + { + _environmentVariables = _environmentVariables ?? new Dictionary(); + + _environmentVariables.Add(name, value); + + return this; + } + + private string GetHostExeName() + { + return $"{s_hostExe}{FileNameSuffixes.CurrentPlatform.Exe}"; + } + } +} diff --git a/src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs b/src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs new file mode 100644 index 000000000..552befdab --- /dev/null +++ b/src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Microsoft.DotNet.Cli.Utils +{ + internal class MSBuildForwardingAppWithoutLogging + { + private const string MSBuildExeName = "MSBuild.dll"; + + private const string SdksDirectoryName = "Sdks"; + + private readonly ForwardingAppImplementation _forwardingApp; + + private readonly Dictionary _msbuildRequiredEnvironmentVariables = + new Dictionary + { + { "MSBuildExtensionsPath", AppContext.BaseDirectory }, + { "CscToolExe", GetRunCscPath() }, + { "MSBuildSDKsPath", GetMSBuildSDKsPath() } + }; + + private readonly IEnumerable _msbuildRequiredParameters = + new List { "/m", "/v:m" }; + + public MSBuildForwardingAppWithoutLogging(IEnumerable argsToForward, string msbuildPath = null) + { + _forwardingApp = new ForwardingAppImplementation( + msbuildPath ?? GetMSBuildExePath(), + _msbuildRequiredParameters.Concat(argsToForward.Select(Escape)), + environmentVariables: _msbuildRequiredEnvironmentVariables); + } + + public virtual ProcessStartInfo GetProcessStartInfo() + { + return _forwardingApp + .GetProcessStartInfo(); + } + + public int Execute() + { + return GetProcessStartInfo().Execute(); + } + + private static string Escape(string arg) => + // this is a workaround for https://github.com/Microsoft/msbuild/issues/1622 + (arg.StartsWith("/p:RestoreSources=", StringComparison.OrdinalIgnoreCase)) ? + arg.Replace(";", "%3B") + .Replace("://", ":%2F%2F") : + arg; + + private static string GetMSBuildExePath() + { + return Path.Combine( + AppContext.BaseDirectory, + MSBuildExeName); + } + + private static string GetMSBuildSDKsPath() + { + var envMSBuildSDKsPath = Environment.GetEnvironmentVariable("MSBuildSDKsPath"); + + if (envMSBuildSDKsPath != null) + { + return envMSBuildSDKsPath; + } + + return Path.Combine( + AppContext.BaseDirectory, + SdksDirectoryName); + } + + private static string GetRunCscPath() + { + var scriptExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".cmd" : ".sh"; + return Path.Combine(AppContext.BaseDirectory, "Roslyn", $"RunCsc{scriptExtension}"); + } + } +} + diff --git a/src/dotnet/ProcessStartInfoExtensions.cs b/src/Microsoft.DotNet.Cli.Utils/ProcessStartInfoExtensions.cs similarity index 95% rename from src/dotnet/ProcessStartInfoExtensions.cs rename to src/Microsoft.DotNet.Cli.Utils/ProcessStartInfoExtensions.cs index cb8e0de83..0805a7b41 100644 --- a/src/dotnet/ProcessStartInfoExtensions.cs +++ b/src/Microsoft.DotNet.Cli.Utils/ProcessStartInfoExtensions.cs @@ -4,7 +4,7 @@ using System; using System.Diagnostics; -namespace Microsoft.DotNet.Cli +namespace Microsoft.DotNet.Cli.Utils { internal static class ProcessStartInfoExtensions { diff --git a/src/dotnet/ForwardingApp.cs b/src/dotnet/ForwardingApp.cs index 2ae292b75..6b44c650e 100644 --- a/src/dotnet/ForwardingApp.cs +++ b/src/dotnet/ForwardingApp.cs @@ -1,28 +1,14 @@ -// 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.Cli.Utils; +using System; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.DotNet.Cli.Utils; +using System.Text; namespace Microsoft.DotNet.Cli { - /// - /// A class which encapsulates logic needed to forward arguments from the current process to another process - /// invoked with the dotnet.exe host. - /// public class ForwardingApp { - private const string s_hostExe = "dotnet"; - - private readonly string _forwardApplicationPath; - private readonly IEnumerable _argsToForward; - private readonly string _depsFile; - private readonly string _runtimeConfig; - private readonly string _additionalProbingPath; - private Dictionary _environmentVariables; - - private readonly string[] _allArgs; + ForwardingAppImplementation _implementation; public ForwardingApp( string forwardApplicationPath, @@ -32,77 +18,29 @@ namespace Microsoft.DotNet.Cli string additionalProbingPath = null, Dictionary environmentVariables = null) { - _forwardApplicationPath = forwardApplicationPath; - _argsToForward = argsToForward; - _depsFile = depsFile; - _runtimeConfig = runtimeConfig; - _additionalProbingPath = additionalProbingPath; - _environmentVariables = environmentVariables; - - var allArgs = new List(); - allArgs.Add("exec"); - - if (_depsFile != null) - { - allArgs.Add("--depsfile"); - allArgs.Add(_depsFile); - } - - if (_runtimeConfig != null) - { - allArgs.Add("--runtimeconfig"); - allArgs.Add(_runtimeConfig); - } - - if (_additionalProbingPath != null) - { - allArgs.Add("--additionalprobingpath"); - allArgs.Add(_additionalProbingPath); - } - - allArgs.Add(_forwardApplicationPath); - allArgs.AddRange(_argsToForward); - - _allArgs = allArgs.ToArray(); - } - - public int Execute() - { - return GetProcessStartInfo().Execute(); + _implementation = new ForwardingAppImplementation( + forwardApplicationPath, + argsToForward, + depsFile, + runtimeConfig, + additionalProbingPath, + environmentVariables); } public ProcessStartInfo GetProcessStartInfo() { - var processInfo = new ProcessStartInfo - { - FileName = GetHostExeName(), - Arguments = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(_allArgs), - UseShellExecute = false - }; - - if (_environmentVariables != null) - { - foreach (var entry in _environmentVariables) - { - processInfo.Environment[entry.Key] = entry.Value; - } - } - - return processInfo; + return _implementation.GetProcessStartInfo(); } public ForwardingApp WithEnvironmentVariable(string name, string value) { - _environmentVariables = _environmentVariables ?? new Dictionary(); - - _environmentVariables.Add(name, value); - + _implementation = _implementation.WithEnvironmentVariable(name, value); return this; } - private string GetHostExeName() + public int Execute() { - return $"{s_hostExe}{FileNameSuffixes.CurrentPlatform.Exe}"; + return _implementation.Execute(); } } } diff --git a/src/dotnet/NuGetForwardingApp.cs b/src/dotnet/NuGetForwardingApp.cs index 04e86623a..bf5852f75 100644 --- a/src/dotnet/NuGetForwardingApp.cs +++ b/src/dotnet/NuGetForwardingApp.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools { diff --git a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs index 78b2e5861..c4e42fe2d 100644 --- a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs +++ b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs @@ -10,6 +10,7 @@ using System.Runtime.InteropServices; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.CommandLine; using System.Diagnostics; +using Microsoft.DotNet.Cli.Utils; namespace Microsoft.DotNet.Tools.MSBuild { @@ -17,24 +18,9 @@ namespace Microsoft.DotNet.Tools.MSBuild { internal const string TelemetrySessionIdEnvironmentVariableName = "DOTNET_CLI_TELEMETRY_SESSIONID"; - private const string MSBuildExeName = "MSBuild.dll"; + private MSBuildForwardingAppWithoutLogging _forwardingAppWithoutLogging; - private const string SdksDirectoryName = "Sdks"; - - private readonly ForwardingApp _forwardingApp; - - private readonly Dictionary _msbuildRequiredEnvironmentVariables = - new Dictionary - { - { "MSBuildExtensionsPath", AppContext.BaseDirectory }, - { "CscToolExe", GetRunCscPath() }, - { "MSBuildSDKsPath", GetMSBuildSDKsPath() } - }; - - private readonly IEnumerable _msbuildRequiredParameters = - new List { "/m", "/v:m" }; - - public MSBuildForwardingApp(IEnumerable argsToForward, string msbuildPath = null) + static IEnumerable ConcatTelemetryLogger(IEnumerable argsToForward) { if (Telemetry.CurrentSessionId != null) { @@ -42,7 +28,7 @@ namespace Microsoft.DotNet.Tools.MSBuild { Type loggerType = typeof(MSBuildLogger); - argsToForward = argsToForward + return argsToForward .Concat(new[] { $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" @@ -53,57 +39,28 @@ namespace Microsoft.DotNet.Tools.MSBuild // Exceptions during telemetry shouldn't cause anything else to fail } } + return argsToForward; + } - _forwardingApp = new ForwardingApp( - msbuildPath ?? GetMSBuildExePath(), - _msbuildRequiredParameters.Concat(argsToForward.Select(Escape)), - environmentVariables: _msbuildRequiredEnvironmentVariables); + public MSBuildForwardingApp(IEnumerable argsToForward, string msbuildPath = null) + { + _forwardingAppWithoutLogging = new MSBuildForwardingAppWithoutLogging( + ConcatTelemetryLogger(argsToForward), + msbuildPath); } public ProcessStartInfo GetProcessStartInfo() { - return _forwardingApp - .WithEnvironmentVariable(TelemetrySessionIdEnvironmentVariableName, Telemetry.CurrentSessionId) - .GetProcessStartInfo(); + var ret = _forwardingAppWithoutLogging.GetProcessStartInfo(); + + ret.Environment[TelemetrySessionIdEnvironmentVariableName] = Telemetry.CurrentSessionId; + + return ret; } public int Execute() { return GetProcessStartInfo().Execute(); } - - private static string Escape(string arg) => - // this is a workaround for https://github.com/Microsoft/msbuild/issues/1622 - (arg.StartsWith("/p:RestoreSources=", StringComparison.OrdinalIgnoreCase)) ? - arg.Replace(";", "%3B") - .Replace("://", ":%2F%2F") : - arg; - - private static string GetMSBuildExePath() - { - return Path.Combine( - AppContext.BaseDirectory, - MSBuildExeName); - } - - private static string GetMSBuildSDKsPath() - { - var envMSBuildSDKsPath = Environment.GetEnvironmentVariable("MSBuildSDKsPath"); - - if (envMSBuildSDKsPath != null) - { - return envMSBuildSDKsPath; - } - - return Path.Combine( - AppContext.BaseDirectory, - SdksDirectoryName); - } - - private static string GetRunCscPath() - { - var scriptExtension = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".cmd" : ".sh"; - return Path.Combine(AppContext.BaseDirectory, "Roslyn", $"RunCsc{scriptExtension}"); - } } } From 5c679cd32e2efa3fd8b8dcef5aef4b45f96757ed Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 21 Apr 2017 16:14:44 -0700 Subject: [PATCH 03/17] Test fixes for tools deps.json generation --- .../ProjectToolsCommandResolver.cs | 17 ++++++++++++++++- .../LocalizableStrings.cs | 2 ++ .../GivenAProjectToolsCommandResolver.cs | 10 +++++++++- .../GivenDotnetMSBuildBuildsProjects.cs | 11 +++++++++-- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs index d95cfead2..41688de82 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs @@ -316,6 +316,12 @@ namespace Microsoft.DotNet.Cli.Utils SingleProjectInfo toolLibrary, string toolDepsJsonGeneratorProject) { + if (string.IsNullOrEmpty(toolDepsJsonGeneratorProject) || + !File.Exists(toolDepsJsonGeneratorProject)) + { + throw new GracefulException(LocalizableStrings.DepsJsonGeneratorProjectNotSet); + } + Reporter.Verbose.WriteLine(string.Format( LocalizableStrings.GeneratingDepsJson, depsPath)); @@ -332,6 +338,9 @@ namespace Microsoft.DotNet.Cli.Utils args.Add($"/p:ToolName={toolLibrary.Name}"); args.Add($"/p:ProjectDepsFilePath={tempDepsFile}"); + var toolTargetFramework = toolLockFile.Targets.First().TargetFramework.GetShortFolderName(); + args.Add($"/p:TargetFramework={toolTargetFramework}"); + // Look for the .props file in the Microsoft.NETCore.App package, until NuGet // generates .props and .targets files for tool restores (https://github.com/NuGet/Home/issues/5037) @@ -364,7 +373,13 @@ namespace Microsoft.DotNet.Cli.Utils // will think the deps file is up-to-date and skip executing File.Delete(tempDepsFile); - var result = new MSBuildForwardingAppWithoutLogging(args).Execute(); + var msBuildExePath = _environment.GetEnvironmentVariable(Constants.MSBUILD_EXE_PATH); + + msBuildExePath = string.IsNullOrEmpty(msBuildExePath) ? + Path.Combine(AppContext.BaseDirectory, "MSBuild.dll") : + msBuildExePath; + + var result = new MSBuildForwardingAppWithoutLogging(args, msBuildExePath).Execute(); if (result != 0) { diff --git a/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs b/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs index 8a3e20014..4667dd19b 100644 --- a/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs +++ b/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs @@ -61,6 +61,8 @@ namespace Microsoft.DotNet.Cli.Utils public const string UnableToGenerateDepsJson = "unable to generate deps.json, it may have been already generated: {0}"; + public const string DepsJsonGeneratorProjectNotSet = "Unable to find deps.json generator project."; + public const string UnableToDeleteTemporaryDepsJson = "unable to delete temporary deps.json file: {0}"; public const string VersionForPackageCouldNotBeResolved = "Version for package `{0}` could not be resolved."; diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs index 938ad5075..a621e02bb 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs @@ -281,7 +281,8 @@ namespace Microsoft.DotNet.Tests lockFile, s_toolPackageFramework, depsJsonFile, - new SingleProjectInfo("dotnet-portable", "1.0.0", Enumerable.Empty())); + new SingleProjectInfo("dotnet-portable", "1.0.0", Enumerable.Empty()), + GetToolDepsJsonGeneratorProject()); File.ReadAllText(depsJsonFile).Should().Be("temp"); File.Delete(depsJsonFile); @@ -456,5 +457,12 @@ namespace Microsoft.DotNet.Tests return projectToolsCommandResolver; } + + private string GetToolDepsJsonGeneratorProject() + { + // When using the product, the ToolDepsJsonGeneratorProject property is used to get this path, but for testing + // we'll hard code the path inside the SDK since we don't have a project to evaluate here + return Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, @"Sdks\Microsoft.NET.Sdk\build\GenerateDeps\GenerateDeps.proj"); + } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs index 41622c72f..51e7017b1 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs @@ -14,6 +14,8 @@ using NuGet.Protocol; using Xunit; using Xunit.Abstractions; using MSBuildCommand = Microsoft.DotNet.Tools.Test.Utilities.MSBuildCommand; +using System.Diagnostics; +using System.Threading; namespace Microsoft.DotNet.Cli.MSBuild.Tests { @@ -164,11 +166,16 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests MSBuildForwardingApp msBuildForwardingApp = new MSBuildForwardingApp(Enumerable.Empty()); - FieldInfo forwardingAppFieldInfo = msBuildForwardingApp + object forwardingAppWithoutLogging = msBuildForwardingApp + .GetType() + .GetField("_forwardingAppWithoutLogging", BindingFlags.Instance | BindingFlags.NonPublic) + ?.GetValue(msBuildForwardingApp); + + FieldInfo forwardingAppFieldInfo = forwardingAppWithoutLogging .GetType() .GetField("_forwardingApp", BindingFlags.Instance | BindingFlags.NonPublic); - ForwardingApp forwardingApp = forwardingAppFieldInfo?.GetValue(msBuildForwardingApp) as ForwardingApp; + object forwardingApp = forwardingAppFieldInfo?.GetValue(forwardingAppWithoutLogging); FieldInfo allArgsFieldinfo = forwardingApp? .GetType() From ea7d84fbcae7e7aa9c024288a255b8dfa14221ea Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Mon, 24 Apr 2017 10:59:13 -0700 Subject: [PATCH 04/17] Remove unnecessary RuntimeFrameworkVersion and DotnetCliToolTargetFramework from test assets --- TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj | 1 - .../AppThrowingException/App/AppThrowingException.csproj | 1 - .../AppDependingOnOtherAsTool.csproj | 2 -- .../AppWithNonExistingToolDependency.csproj | 1 - .../AppWithDepOnTool/AppWithDepOnTool.csproj | 2 -- .../ToolWithRandomPackageName.csproj | 1 - .../TestPackages/ToolWithOutputName/ToolWithOutputName.csproj | 1 - .../dotnet-fallbackfoldertool.csproj | 1 - .../dotnet-hello/v1/dotnet-hello/dotnet-hello.csproj | 1 - .../dotnet-hello/v2/dotnet-hello/dotnet-hello.csproj | 1 - .../TestPackages/dotnet-portable/dotnet-portable.csproj | 1 - .../dotnet-prefercliruntime/dotnet-prefercliruntime.csproj | 1 - .../AppWithDepOnToolWithOutputName.csproj | 2 -- .../AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj | 2 -- .../TestProjects/AppWithDirectDep/AppWithDirectDep.csproj | 2 -- .../AppWithDirectDepWithOutputName.csproj | 1 - .../AppWithFallbackFolderToolDependency.csproj | 2 -- .../AppWithToolDependency/AppWithToolDependency.csproj | 2 -- .../DependencyContextFromTool.csproj | 1 - .../MSBuildAppWithMultipleFrameworks.csproj | 1 - TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj | 2 -- TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj | 1 - .../TestAppWithProjDepTool/TestAppWithProjDepTool.csproj | 1 - .../VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj | 4 ---- .../TestProjects/VSTestDotNetCore/VSTestDotNetCore.csproj | 1 - .../VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj | 1 - 26 files changed, 37 deletions(-) diff --git a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj index ba40187cd..27d4b3c4d 100644 --- a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj +++ b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj @@ -6,7 +6,6 @@ Exe $(PackageTargetFallback);portable-net45+win8;dnxcore50 win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 - $(CLI_SharedFrameworkVersion) netcoreapp1.1 diff --git a/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj b/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj index d705ebd65..f595af9f3 100644 --- a/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj +++ b/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj @@ -6,7 +6,6 @@ netcoreapp1.0 dotnet-throwingtool $(AssemblyName) - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/NonRestoredTestProjects/AppThrowingException/AppDependingOnOtherAsTool/AppDependingOnOtherAsTool.csproj b/TestAssets/NonRestoredTestProjects/AppThrowingException/AppDependingOnOtherAsTool/AppDependingOnOtherAsTool.csproj index 7159443c2..30c6823e7 100644 --- a/TestAssets/NonRestoredTestProjects/AppThrowingException/AppDependingOnOtherAsTool/AppDependingOnOtherAsTool.csproj +++ b/TestAssets/NonRestoredTestProjects/AppThrowingException/AppDependingOnOtherAsTool/AppDependingOnOtherAsTool.csproj @@ -4,8 +4,6 @@ Exe netcoreapp2.0 - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/AppWithNonExistingToolDependency.csproj b/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/AppWithNonExistingToolDependency.csproj index 11553b268..db9d6f117 100644 --- a/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/AppWithNonExistingToolDependency.csproj +++ b/TestAssets/NonRestoredTestProjects/AppWithNonExistingToolDependency/AppWithNonExistingToolDependency.csproj @@ -4,7 +4,6 @@ Exe netcoreapp2.0 - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/AppWithDepOnTool/AppWithDepOnTool.csproj b/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/AppWithDepOnTool/AppWithDepOnTool.csproj index f62de8419..f5ab2f51a 100644 --- a/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/AppWithDepOnTool/AppWithDepOnTool.csproj +++ b/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/AppWithDepOnTool/AppWithDepOnTool.csproj @@ -5,8 +5,6 @@ Exe netcoreapp2.0 random-name - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/ToolWithRandomPackageName/ToolWithRandomPackageName.csproj b/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/ToolWithRandomPackageName/ToolWithRandomPackageName.csproj index 3cbeb2a34..9184414e8 100644 --- a/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/ToolWithRandomPackageName/ToolWithRandomPackageName.csproj +++ b/TestAssets/NonRestoredTestProjects/ToolWithRandomPackageName/ToolWithRandomPackageName/ToolWithRandomPackageName.csproj @@ -7,7 +7,6 @@ random-name $(GeneratedPackageId) dotnet-randompackage - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj b/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj index 4844d4232..5639e3331 100644 --- a/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj +++ b/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj @@ -6,7 +6,6 @@ dotnet-tool-with-output-name ToolWithOutputName Exe - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj b/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj index b7049a0ca..11aac9cf0 100644 --- a/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj +++ b/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj @@ -6,7 +6,6 @@ dotnet-fallbackfoldertool Exe - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello/dotnet-hello.csproj b/TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello/dotnet-hello.csproj index 8a5096465..fd5621f08 100644 --- a/TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello/dotnet-hello.csproj +++ b/TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello/dotnet-hello.csproj @@ -6,7 +6,6 @@ netcoreapp2.0 - $(CLI_SharedFrameworkVersion) dotnet-hello Exe win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 diff --git a/TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello/dotnet-hello.csproj b/TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello/dotnet-hello.csproj index 8f8164cef..2391dfc1b 100644 --- a/TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello/dotnet-hello.csproj +++ b/TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello/dotnet-hello.csproj @@ -6,7 +6,6 @@ netcoreapp2.0 - $(CLI_SharedFrameworkVersion) dotnet-hello Exe win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 diff --git a/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj b/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj index 6ec578ca4..cfbee8a50 100644 --- a/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj +++ b/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj @@ -6,7 +6,6 @@ dotnet-portable Exe - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj b/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj index 9b9f2fec9..bd65e4cdd 100644 --- a/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj +++ b/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj @@ -5,7 +5,6 @@ netcoreapp2.0 Exe - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj b/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj index c1d0bb41a..9adf4c6fc 100755 --- a/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj +++ b/TestAssets/TestProjects/AppWithDepOnToolWithOutputName/AppWithDepOnToolWithOutputName.csproj @@ -4,8 +4,6 @@ netcoreapp2.0 Exe - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj b/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj index 8795839bc..df284421b 100755 --- a/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj +++ b/TestAssets/TestProjects/AppWithDirectAndToolDep/AppWithDirectAndToolDep.csproj @@ -4,8 +4,6 @@ netcoreapp2.0 Exe - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj b/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj index 0ca6ef86f..6995199ee 100755 --- a/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj +++ b/TestAssets/TestProjects/AppWithDirectDep/AppWithDirectDep.csproj @@ -7,8 +7,6 @@ AppWithDirectDep Exe false - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj b/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj index 4f189d465..60a496f1e 100755 --- a/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj +++ b/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj @@ -4,7 +4,6 @@ netcoreapp2.0 Exe - $(CLI_SharedFrameworkVersion) netcoreapp1.1 diff --git a/TestAssets/TestProjects/AppWithFallbackFolderToolDependency/AppWithFallbackFolderToolDependency.csproj b/TestAssets/TestProjects/AppWithFallbackFolderToolDependency/AppWithFallbackFolderToolDependency.csproj index 706240e90..705cf2077 100755 --- a/TestAssets/TestProjects/AppWithFallbackFolderToolDependency/AppWithFallbackFolderToolDependency.csproj +++ b/TestAssets/TestProjects/AppWithFallbackFolderToolDependency/AppWithFallbackFolderToolDependency.csproj @@ -4,8 +4,6 @@ netcoreapp2.0 Exe - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj b/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj index f3506fae4..7f9c16848 100755 --- a/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj +++ b/TestAssets/TestProjects/AppWithToolDependency/AppWithToolDependency.csproj @@ -4,8 +4,6 @@ netcoreapp2.0 Exe - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj b/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj index 909f6aa9f..3a74bcca2 100755 --- a/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj +++ b/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj @@ -8,7 +8,6 @@ Exe false $(PackageTargetFallback);dnxcore50;portable-net45+win8 - $(CLI_SharedFrameworkVersion) netcoreapp1.1 diff --git a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj index 255d7f570..89aae6c65 100644 --- a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj +++ b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworks/MSBuildAppWithMultipleFrameworks.csproj @@ -4,7 +4,6 @@ Exe net451;netcoreapp2.0 - $(CLI_SharedFrameworkVersion) \ No newline at end of file diff --git a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj index 1f9b629d4..79bceb82d 100644 --- a/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj +++ b/TestAssets/TestProjects/MSBuildTestApp/MSBuildTestApp.csproj @@ -5,8 +5,6 @@ Exe netcoreapp2.0 win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 - $(CLI_SharedFrameworkVersion) - netcoreapp2.0 diff --git a/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj b/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj index 4f0d4e8e5..302abe3bc 100755 --- a/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj +++ b/TestAssets/TestProjects/TestAppSimple/TestAppSimple.csproj @@ -4,7 +4,6 @@ netcoreapp2.0 Exe - $(CLI_SharedFrameworkVersion) true diff --git a/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj b/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj index bedcf3da2..ee366323a 100644 --- a/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj +++ b/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj @@ -4,7 +4,6 @@ Exe netcoreapp2.0 - $(CLI_SharedFrameworkVersion) netcoreapp1.1 diff --git a/TestAssets/TestProjects/VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj b/TestAssets/TestProjects/VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj index 84252d545..9cd7184f8 100644 --- a/TestAssets/TestProjects/VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj +++ b/TestAssets/TestProjects/VSTestDesktopAndNetCore/VSTestDesktopAndNetCore.csproj @@ -10,10 +10,6 @@ DESKTOP;$(DefineConstants) - - $(CLI_SharedFrameworkVersion) - - diff --git a/TestAssets/TestProjects/VSTestDotNetCore/VSTestDotNetCore.csproj b/TestAssets/TestProjects/VSTestDotNetCore/VSTestDotNetCore.csproj index 711143c68..0d07738af 100644 --- a/TestAssets/TestProjects/VSTestDotNetCore/VSTestDotNetCore.csproj +++ b/TestAssets/TestProjects/VSTestDotNetCore/VSTestDotNetCore.csproj @@ -4,7 +4,6 @@ Exe netcoreapp2.0 - $(CLI_SharedFrameworkVersion) diff --git a/TestAssets/TestProjects/VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj b/TestAssets/TestProjects/VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj index ae4226e6c..d6016beea 100644 --- a/TestAssets/TestProjects/VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj +++ b/TestAssets/TestProjects/VSTestXunitDotNetCore/VSTestXunitDotNetCore.csproj @@ -4,7 +4,6 @@ Exe netcoreapp2.0 - $(CLI_SharedFrameworkVersion) From 8615c300631eb058933c0a76bb9e78ee19d075ea Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Mon, 24 Apr 2017 23:09:45 -0700 Subject: [PATCH 05/17] Don't roll prefercliruntime tools forward across major versions of .NET Core --- ...ackagedCommandSpecFactoryWithCliRuntime.cs | 38 +++++++++++++++++-- .../LocalizableStrings.cs | 2 + 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs index a081bcd30..660fc1b94 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs @@ -21,11 +21,43 @@ namespace Microsoft.DotNet.Cli.Utils { if(PrefersCliRuntime(commandPath)) { - arguments.Add("--fx-version"); - arguments.Add(new Muxer().SharedFxVersion); + var runtimeConfigFile = Path.ChangeExtension(commandPath, FileNameSuffixes.RuntimeConfigJson); + var runtimeConfig = new RuntimeConfig(runtimeConfigFile); + + var muxer = new Muxer(); + + Version currentFrameworkSimpleVersion = GetVersionWithoutPrerelease(muxer.SharedFxVersion); + Version toolFrameworkSimpleVersion = GetVersionWithoutPrerelease(runtimeConfig.Framework.Version); + + if (currentFrameworkSimpleVersion.Major != toolFrameworkSimpleVersion.Major) + { + Reporter.Verbose.WriteLine( + string.Format( + LocalizableStrings.IgnoringPreferCLIRuntimeFile, + nameof(PackagedCommandSpecFactory), + runtimeConfig.Framework.Version, + muxer.SharedFxVersion)); + } + else + { + arguments.Add("--fx-version"); + arguments.Add(new Muxer().SharedFxVersion); + } } } + private static Version GetVersionWithoutPrerelease(string version) + { + int dashOrPlusIndex = version.IndexOfAny(new char[] { '-', '+' }); + + if (dashOrPlusIndex >= 0) + { + version = version.Substring(0, dashOrPlusIndex); + } + + return new Version(version); + } + private static bool PrefersCliRuntime(string commandPath) { var libTFMPackageDirectory = Path.GetDirectoryName(commandPath); @@ -35,7 +67,7 @@ namespace Microsoft.DotNet.Cli.Utils Reporter.Verbose.WriteLine( string.Format( LocalizableStrings.LookingForPreferCliRuntimeFile, - "packagedcommandspecfactory", + nameof(PackagedCommandSpecFactory), preferCliRuntimePath)); return File.Exists(preferCliRuntimePath); diff --git a/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs b/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs index 4667dd19b..455920e1b 100644 --- a/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs +++ b/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs @@ -19,6 +19,8 @@ namespace Microsoft.DotNet.Cli.Utils public const string LookingForPreferCliRuntimeFile = "{0}: Looking for prefercliruntime file at `{1}`"; + public const string IgnoringPreferCLIRuntimeFile = "{0}: Ignoring prefercliruntime file as the tool target framework ({1}) has a different major version than the current CLI runtime ({2})"; + public const string AttemptingToResolve = "{0}: attempting to resolve {1}"; public const string DidNotFindAMatchingProject = "{0}: Did not find a matching project {1}."; From 01d3895b24409dbe1f7867a3179420a7d723f4c4 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Tue, 25 Apr 2017 10:03:45 -0700 Subject: [PATCH 06/17] Add tests for behavior of tools that target previous major version of shared framework --- .../dotnet-portable-v1-prefercli.csproj | 23 ++++++ .../dotnet-portable-v1.csproj | 18 +++++ .../TestPackages/dotnet-portable/Program.cs | 8 ++ .../dotnet-portable/dotnet-portable.csproj | 2 - build/test/TestPackageProjects.targets | 18 +++++ ...equiresSpecificFrameworkTheoryAttribute.cs | 19 +++++ test/dotnet.Tests/PackagedCommandTests.cs | 76 +++++++++++++++++++ 7 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj create mode 100644 TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj create mode 100644 test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs diff --git a/TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj b/TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj new file mode 100644 index 000000000..60ef7f71c --- /dev/null +++ b/TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj @@ -0,0 +1,23 @@ + + + + + netcoreapp1.1 + Exe + + + + + $(ProjectRuntimeConfigFilePath) + + + + + + + + true + \prefercliruntime + + + diff --git a/TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj b/TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj new file mode 100644 index 000000000..3df959be1 --- /dev/null +++ b/TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj @@ -0,0 +1,18 @@ + + + + + netcoreapp1.1 + Exe + + + + + $(ProjectRuntimeConfigFilePath) + + + + + + + diff --git a/TestAssets/TestPackages/dotnet-portable/Program.cs b/TestAssets/TestPackages/dotnet-portable/Program.cs index bcb5ed009..d0e978fd2 100644 --- a/TestAssets/TestPackages/dotnet-portable/Program.cs +++ b/TestAssets/TestPackages/dotnet-portable/Program.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.IO; +using System.Reflection; namespace ConsoleApplication { @@ -10,6 +12,12 @@ namespace ConsoleApplication public static void Main(string[] args) { Console.WriteLine("Hello Portable World!"); + + var coreAssembly = typeof(object).GetTypeInfo().Assembly; + string coreFolder = Path.GetDirectoryName(coreAssembly.Location); + string frameworkVersion = Path.GetFileName(coreFolder); + + Console.WriteLine($"I'm running on shared framework version {frameworkVersion}!"); } } } diff --git a/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj b/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj index cfbee8a50..f8b581110 100644 --- a/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj +++ b/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj @@ -3,9 +3,7 @@ netcoreapp2.0 - dotnet-portable Exe - diff --git a/build/test/TestPackageProjects.targets b/build/test/TestPackageProjects.targets index 986fc569a..610d03937 100644 --- a/build/test/TestPackageProjects.targets +++ b/build/test/TestPackageProjects.targets @@ -136,6 +136,24 @@ True + + dotnet-portable + dotnet-portable-v1.csproj + True + True + 1.0.0 + + True + + + dotnet-portable + dotnet-portable-v1-prefercli.csproj + True + True + 1.0.0 + + True + dotnet-fallbackfoldertool dotnet-fallbackfoldertool.csproj diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs new file mode 100644 index 000000000..c2af978d4 --- /dev/null +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs @@ -0,0 +1,19 @@ +using Microsoft.DotNet.Tools.Test.Utilities; +using System; +using System.Collections.Generic; +using System.Text; +using Xunit; + +namespace Microsoft.DotNet.Tools.Test.Utilities +{ + public class RequiresSpecificFrameworkTheoryAttribute : TheoryAttribute + { + public RequiresSpecificFrameworkTheoryAttribute(string framework) + { + if (!EnvironmentInfo.HasSharedFramework(framework)) + { + this.Skip = $"This test requires a shared framework that isn't present: {framework}"; + } + } + } +} diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index e1816ca8f..642ef1364 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -91,6 +91,82 @@ namespace Microsoft.DotNet.Tests .And.Pass(); } + [Theory] + [InlineData(true)] + [InlineData(false)] + public void IfPreviousVersionOfSharedFrameworkIsNotInstalled_ToolsTargetingItFail(bool toolPrefersCLIRuntime) + { + var testInstance = TestAssets.Get("AppWithToolDependency") + .CreateInstance(identifier: toolPrefersCLIRuntime ? "preferCLIRuntime" : "") + .WithSourceFiles() + .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages); + + testInstance = testInstance.WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace; + + var toolReference = project.Descendants(ns + "DotNetCliToolReference") + .Where(tr => tr.Attribute("Include").Value == "dotnet-portable") + .Single(); + + toolReference.Attribute("Include").Value = + toolPrefersCLIRuntime ? "dotnet-portable-v1-prefercli" : "dotnet-portable-v1"; + }); + + testInstance = testInstance.WithRestoreFiles(); + + new BuildCommand() + .WithProjectDirectory(testInstance.Root) + .Execute() + .Should().Pass(); + + new GenericCommand(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1") + .WithWorkingDirectory(testInstance.Root) + .WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0") + .Execute() + .Should().Fail(); + } + + [RequiresSpecificFrameworkTheory("netcoreapp1.1")] + [InlineData(true)] + [InlineData(false)] + public void IfPreviousVersionOfSharedFrameworkIsInstalled_ToolsTargetingItRun(bool toolPrefersCLIRuntime) + { + var testInstance = TestAssets.Get("AppWithToolDependency") + .CreateInstance(identifier: toolPrefersCLIRuntime ? "preferCLIRuntime" : "") + .WithSourceFiles() + .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages); + + testInstance = testInstance.WithProjectChanges(project => + { + var ns = project.Root.Name.Namespace; + + var toolReference = project.Descendants(ns + "DotNetCliToolReference") + .Where(tr => tr.Attribute("Include").Value == "dotnet-portable") + .Single(); + + toolReference.Attribute("Include").Value = + toolPrefersCLIRuntime ? "dotnet-portable-v1-prefercli" : "dotnet-portable-v1"; + }); + + testInstance = testInstance.WithRestoreFiles(); + + new BuildCommand() + .WithProjectDirectory(testInstance.Root) + .Execute() + .Should().Pass(); + + var result = + new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes) + .WithWorkingDirectory(testInstance.Root) + .WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0") + .Execute(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1"); + + result.Should().Pass() + .And.HaveStdOutContaining("I'm running on shared framework version 1.1.1!"); + + } + [Fact] public void CanInvokeToolWhosePackageNameIsDifferentFromDllName() { From 06c1cc5990c11e597e596cbb8c04962030e4b29b Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Tue, 25 Apr 2017 11:20:37 -0700 Subject: [PATCH 07/17] Update test tools that need conflict resolution on 2.0 to target 2.0 --- .../DesktopTestProjects/AppWithProjTool2Fx/App.csproj | 1 - .../AppWithRedirectsAndConfig.csproj | 1 - .../AppWithRedirectsNoConfig.csproj | 1 - .../DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj | 1 - .../dotnet-dependency-context-test.csproj | 8 ++------ .../dotnet-dependency-tool-invoker.csproj | 8 ++------ .../AppWithDirectDepWithOutputName.csproj | 1 - .../MSBuildAppWithMultipleFrameworksAndTools.csproj | 1 - .../DependencyContextFromTool.csproj | 1 - .../MSBuildAppWithMultipleFrameworksAndTools.csproj | 1 - .../TestAppWithProjDepTool/TestAppWithProjDepTool.csproj | 1 - test/EndToEnd/GivenDotNetUsesMSBuild.cs | 2 +- test/dotnet.Tests/PackagedCommandTests.cs | 4 ++-- 13 files changed, 7 insertions(+), 24 deletions(-) diff --git a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj index 27d4b3c4d..f52962bc8 100644 --- a/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj +++ b/TestAssets/DesktopTestProjects/AppWithProjTool2Fx/App.csproj @@ -6,7 +6,6 @@ Exe $(PackageTargetFallback);portable-net45+win8;dnxcore50 win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 - netcoreapp1.1 diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj index 9ab6d1e5a..82a5ad25d 100644 --- a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj +++ b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj @@ -4,7 +4,6 @@ AppWithRedirectsAndConfig Exe win7-x64;win7-x86 - netcoreapp1.1 diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj index aa1b27d15..94b99d56b 100644 --- a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj +++ b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj @@ -4,7 +4,6 @@ AppWithRedirectsNoConfig Exe win7-x64;win7-x86 - netcoreapp1.1 diff --git a/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj b/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj index 51192f708..e0865b59b 100644 --- a/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj +++ b/TestAssets/DesktopTestProjects/LibWithProjTool2Fx/Lib.csproj @@ -3,7 +3,6 @@ netstandard1.6;net451 Library $(PackageTargetFallback);portable-net45+win8;dnxcore50;netcoreapp2.0 - netcoreapp1.1 diff --git a/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj b/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj index 1717cd460..85afeaf74 100644 --- a/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj +++ b/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj @@ -1,14 +1,10 @@  - + 1.0.0-rc - netcoreapp1.1 - dotnet-dependency-context-test + netcoreapp2.0 Exe - $(PackageTargetFallback);dnxcore50;portable-net45+win8 - 1.1.1 - false diff --git a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj index 23df5a2ee..35b569560 100644 --- a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj +++ b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj @@ -1,15 +1,11 @@  - + 1.0.0-rc - netcoreapp1.1 - dotnet-dependency-tool-invoker + netcoreapp2.0 Exe - $(PackageTargetFallback);portable-net45+win8;dnxcore50 - 1.1.1 - false diff --git a/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj b/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj index 60a496f1e..5afb24921 100755 --- a/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj +++ b/TestAssets/TestProjects/AppWithDirectDepWithOutputName/AppWithDirectDepWithOutputName.csproj @@ -4,7 +4,6 @@ netcoreapp2.0 Exe - netcoreapp1.1 diff --git a/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj b/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj index db7004ecd..33cb2b5a7 100644 --- a/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj +++ b/TestAssets/TestProjects/AppWithMultipleFxAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj @@ -4,7 +4,6 @@ Exe net451;netcoreapp2.0 - netcoreapp1.1 diff --git a/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj b/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj index 3a74bcca2..5dfd70f43 100755 --- a/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj +++ b/TestAssets/TestProjects/DependencyContextFromTool/DependencyContextFromTool.csproj @@ -8,7 +8,6 @@ Exe false $(PackageTargetFallback);dnxcore50;portable-net45+win8 - netcoreapp1.1 diff --git a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj index 5c26acade..766c1ae66 100644 --- a/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj +++ b/TestAssets/TestProjects/MSBuildAppWithMultipleFrameworksAndTools/MSBuildAppWithMultipleFrameworksAndTools.csproj @@ -4,7 +4,6 @@ Exe net451;netcoreapp2.0 - netcoreapp1.1 diff --git a/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj b/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj index ee366323a..3f8176791 100644 --- a/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj +++ b/TestAssets/TestProjects/TestAppWithProjDepTool/TestAppWithProjDepTool.csproj @@ -4,7 +4,6 @@ Exe netcoreapp2.0 - netcoreapp1.1 diff --git a/test/EndToEnd/GivenDotNetUsesMSBuild.cs b/test/EndToEnd/GivenDotNetUsesMSBuild.cs index 86d19e0c3..f714ee38c 100644 --- a/test/EndToEnd/GivenDotNetUsesMSBuild.cs +++ b/test/EndToEnd/GivenDotNetUsesMSBuild.cs @@ -89,7 +89,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd .And.HaveStdOutContaining("Hello I prefer the cli runtime World!");; } - [RequiresSpecificFrameworkFact("netcoreapp1.1")] // https://github.com/dotnet/cli/issues/6087 + [Fact] public void ItCanRunAToolThatInvokesADependencyToolInACSProj() { var repoDirectoriesProvider = new RepoDirectoriesProvider(); diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index 642ef1364..e0f1cd2c5 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -188,7 +188,7 @@ namespace Microsoft.DotNet.Tests .And.Pass(); } - [RequiresSpecificFrameworkFact("netcoreapp1.1")] // https://github.com/dotnet/cli/issues/6087 + [Fact] public void CanInvokeToolFromDirectDependenciesIfPackageNameDifferentFromToolName() { var testInstance = TestAssets.Get("AppWithDirectDepWithOutputName") @@ -318,7 +318,7 @@ namespace Microsoft.DotNet.Tests .Should().Fail(); } - [RequiresSpecificFrameworkFact("netcoreapp1.1")] // https://github.com/dotnet/cli/issues/6087 + [Fact] public void ToolsCanAccessDependencyContextProperly() { var testInstance = TestAssets.Get("DependencyContextFromTool") From cc9e942ede3df06c70fc3a25613e85cc071f189d Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 26 Apr 2017 14:57:18 -0700 Subject: [PATCH 08/17] Apply code review feedback --- TestAssets/TestPackages/dotnet-portable/Program.cs | 14 +++++++++++--- .../IPackagedCommandSpecFactory.cs | 2 -- .../PackagedCommandSpecFactoryWithCliRuntime.cs | 2 +- .../Extensions/LockFileExtensions.cs | 5 ++++- .../ForwardingAppImplementation.cs | 4 ++-- .../MSBuildForwardingAppWithoutLogging.cs | 5 ++++- src/dotnet/ForwardingApp.cs | 7 +++++-- .../dotnet-msbuild/MSBuildForwardingApp.cs | 2 +- .../GivenAProjectToolsCommandResolver.cs | 2 +- .../RequiresSpecificFrameworkTheoryAttribute.cs | 5 ++++- 10 files changed, 33 insertions(+), 15 deletions(-) diff --git a/TestAssets/TestPackages/dotnet-portable/Program.cs b/TestAssets/TestPackages/dotnet-portable/Program.cs index d0e978fd2..1c8fb26e7 100644 --- a/TestAssets/TestPackages/dotnet-portable/Program.cs +++ b/TestAssets/TestPackages/dotnet-portable/Program.cs @@ -13,11 +13,19 @@ namespace ConsoleApplication { Console.WriteLine("Hello Portable World!"); - var coreAssembly = typeof(object).GetTypeInfo().Assembly; - string coreFolder = Path.GetDirectoryName(coreAssembly.Location); - string frameworkVersion = Path.GetFileName(coreFolder); + var depsFile = new FileInfo(GetDataFromAppDomain("FX_DEPS_FILE")); + string frameworkVersion = depsFile.Directory.Name; Console.WriteLine($"I'm running on shared framework version {frameworkVersion}!"); } + + public static string GetDataFromAppDomain(string propertyName) + { + var appDomainType = typeof(object).GetTypeInfo().Assembly?.GetType("System.AppDomain"); + var currentDomain = appDomainType?.GetProperty("CurrentDomain")?.GetValue(null); + var deps = appDomainType?.GetMethod("GetData")?.Invoke(currentDomain, new[] { propertyName }); + + return deps as string; + } } } diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs index 15ed9fde5..5f409a09f 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs @@ -8,8 +8,6 @@ namespace Microsoft.DotNet.Cli.Utils { public interface IPackagedCommandSpecFactory { - // Code review TODO: Is it OK to make breaking changes to the CLI Utils API surface? - CommandSpec CreateCommandSpecFromLibrary( LockFileTargetLibrary toolLibrary, string commandName, diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs index 660fc1b94..0d7edc4e3 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs @@ -41,7 +41,7 @@ namespace Microsoft.DotNet.Cli.Utils else { arguments.Add("--fx-version"); - arguments.Add(new Muxer().SharedFxVersion); + arguments.Add(muxer.SharedFxVersion); } } } diff --git a/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs b/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs index 5b504badf..a54a502a9 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Extensions/LockFileExtensions.cs @@ -1,4 +1,7 @@ -using Microsoft.DotNet.Tools.Common; +// 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.Tools.Common; using NuGet.Packaging; using NuGet.ProjectModel; using System; diff --git a/src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs b/src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs index cb5098bc0..72e65aa3c 100644 --- a/src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs +++ b/src/Microsoft.DotNet.Cli.Utils/ForwardingAppImplementation.cs @@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Utils /// internal class ForwardingAppImplementation { - private const string s_hostExe = "dotnet"; + private const string HostExe = "dotnet"; private readonly string _forwardApplicationPath; private readonly IEnumerable _argsToForward; @@ -102,7 +102,7 @@ namespace Microsoft.DotNet.Cli.Utils private string GetHostExeName() { - return $"{s_hostExe}{FileNameSuffixes.CurrentPlatform.Exe}"; + return $"{HostExe}{FileNameSuffixes.CurrentPlatform.Exe}"; } } } diff --git a/src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs b/src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs index 552befdab..351ce43af 100644 --- a/src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs +++ b/src/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs @@ -1,4 +1,7 @@ -using System; +// 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 System.Diagnostics; using System.IO; diff --git a/src/dotnet/ForwardingApp.cs b/src/dotnet/ForwardingApp.cs index 6b44c650e..25d3cff58 100644 --- a/src/dotnet/ForwardingApp.cs +++ b/src/dotnet/ForwardingApp.cs @@ -1,4 +1,7 @@ -using Microsoft.DotNet.Cli.Utils; +// 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.Cli.Utils; using System; using System.Collections.Generic; using System.Diagnostics; @@ -8,7 +11,7 @@ namespace Microsoft.DotNet.Cli { public class ForwardingApp { - ForwardingAppImplementation _implementation; + private ForwardingAppImplementation _implementation; public ForwardingApp( string forwardApplicationPath, diff --git a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs index c4e42fe2d..b3edf4abe 100644 --- a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs +++ b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Tools.MSBuild private MSBuildForwardingAppWithoutLogging _forwardingAppWithoutLogging; - static IEnumerable ConcatTelemetryLogger(IEnumerable argsToForward) + private static IEnumerable ConcatTelemetryLogger(IEnumerable argsToForward) { if (Telemetry.CurrentSessionId != null) { diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs index a621e02bb..11eca166a 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAProjectToolsCommandResolver.cs @@ -462,7 +462,7 @@ namespace Microsoft.DotNet.Tests { // When using the product, the ToolDepsJsonGeneratorProject property is used to get this path, but for testing // we'll hard code the path inside the SDK since we don't have a project to evaluate here - return Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, @"Sdks\Microsoft.NET.Sdk\build\GenerateDeps\GenerateDeps.proj"); + return Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, "Sdks", "Microsoft.NET.Sdk", "build", "GenerateDeps", "GenerateDeps.proj"); } } } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs index c2af978d4..52166156b 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/RequiresSpecificFrameworkTheoryAttribute.cs @@ -1,4 +1,7 @@ -using Microsoft.DotNet.Tools.Test.Utilities; +// 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.Tools.Test.Utilities; using System; using System.Collections.Generic; using System.Text; From 4bf34512f854931ff66cdbef604103b2dd259e7b Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 26 Apr 2017 14:57:46 -0700 Subject: [PATCH 09/17] Fix test asset which depends on SdkNuGetVersion property --- .../dotnet-dependency-tool-invoker.csproj | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj index 35b569560..2ce9e3b1a 100644 --- a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj +++ b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj @@ -1,11 +1,15 @@  - + + + 1.0.0-rc netcoreapp2.0 Exe + false From 0afd0b997525a86b6c60a5dea749e2c9ef49439e Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 26 Apr 2017 15:41:23 -0700 Subject: [PATCH 10/17] Remove dead code --- .../CommandResolution/DepsJsonBuilder.cs | 315 ------------------ .../ProjectToolsCommandResolver.cs | 3 - 2 files changed, 318 deletions(-) delete mode 100644 src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonBuilder.cs diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonBuilder.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonBuilder.cs deleted file mode 100644 index c9a69f0c8..000000000 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/DepsJsonBuilder.cs +++ /dev/null @@ -1,315 +0,0 @@ -// 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 System.Linq; -using System.Security.Cryptography; -using System.Text; -using Microsoft.Extensions.DependencyModel; -using NuGet.Frameworks; -using NuGet.Packaging; -using NuGet.Packaging.Core; -using NuGet.ProjectModel; - -namespace Microsoft.DotNet.Cli.Utils -{ - internal class DepsJsonBuilder - { - private readonly VersionFolderPathResolver _versionFolderPathResolver; - - public DepsJsonBuilder() - { - // This resolver is only used for building file names, so that base path is not required. - _versionFolderPathResolver = new VersionFolderPathResolver(rootPath: null); - } - - public DependencyContext Build( - SingleProjectInfo mainProjectInfo, - CompilationOptions compilationOptions, - LockFile lockFile, - NuGetFramework framework, - string runtime) - { - bool includeCompilationLibraries = compilationOptions != null; - - LockFileTarget lockFileTarget = lockFile.GetTarget(framework, runtime); - - IEnumerable runtimeExports = lockFileTarget.GetRuntimeLibraries(); - IEnumerable compilationExports = - includeCompilationLibraries ? - lockFileTarget.GetCompileLibraries() : - Enumerable.Empty(); - - var dependencyLookup = compilationExports - .Concat(runtimeExports) - .Distinct() - .Select(library => new Dependency(library.Name, library.Version.ToString())) - .ToDictionary(dependency => dependency.Name, StringComparer.OrdinalIgnoreCase); - - var libraryLookup = lockFile.Libraries.ToDictionary(l => l.Name, StringComparer.OrdinalIgnoreCase); - - var runtimeSignature = GenerateRuntimeSignature(runtimeExports); - - IEnumerable runtimeLibraries = - GetLibraries(runtimeExports, libraryLookup, dependencyLookup, runtime: true).Cast(); - - IEnumerable compilationLibraries; - if (includeCompilationLibraries) - { - CompilationLibrary projectCompilationLibrary = GetProjectCompilationLibrary( - mainProjectInfo, - lockFile, - lockFileTarget, - dependencyLookup); - compilationLibraries = new[] { projectCompilationLibrary } - .Concat( - GetLibraries(compilationExports, libraryLookup, dependencyLookup, runtime: false) - .Cast()); - } - else - { - compilationLibraries = Enumerable.Empty(); - } - - return new DependencyContext( - new TargetInfo(framework.DotNetFrameworkName, runtime, runtimeSignature, lockFileTarget.IsPortable()), - compilationOptions ?? CompilationOptions.Default, - compilationLibraries, - runtimeLibraries, - new RuntimeFallbacks[] { }); - } - - private static string GenerateRuntimeSignature(IEnumerable runtimeExports) - { - var sha1 = SHA1.Create(); - var builder = new StringBuilder(); - var packages = runtimeExports - .Where(libraryExport => libraryExport.Type == "package"); - var separator = "|"; - foreach (var libraryExport in packages) - { - builder.Append(libraryExport.Name); - builder.Append(separator); - builder.Append(libraryExport.Version.ToString()); - builder.Append(separator); - } - var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(builder.ToString())); - - builder.Clear(); - foreach (var hashByte in hash) - { - builder.AppendFormat("{0:x2}", hashByte); - } - return builder.ToString(); - } - - private List GetProjectDependencies( - LockFile lockFile, - LockFileTarget lockFileTarget, - Dictionary dependencyLookup) - { - - List dependencies = new List(); - - IEnumerable projectFileDependencies = lockFile - .ProjectFileDependencyGroups - .Where(dg => dg.FrameworkName == string.Empty || - dg.FrameworkName == lockFileTarget.TargetFramework.DotNetFrameworkName); - - foreach (string projectFileDependency in projectFileDependencies.SelectMany(dg => dg.Dependencies)) - { - int separatorIndex = projectFileDependency.IndexOf(' '); - string dependencyName = separatorIndex > 0 ? - projectFileDependency.Substring(0, separatorIndex) : - projectFileDependency; - - Dependency dependency; - if (dependencyLookup.TryGetValue(dependencyName, out dependency)) - { - dependencies.Add(dependency); - } - } - - return dependencies; - } - - private RuntimeLibrary GetProjectRuntimeLibrary( - SingleProjectInfo projectInfo, - LockFile lockFile, - LockFileTarget lockFileTarget, - Dictionary dependencyLookup) - { - - RuntimeAssetGroup[] runtimeAssemblyGroups = new[] { new RuntimeAssetGroup(string.Empty, projectInfo.GetOutputName()) }; - - List dependencies = GetProjectDependencies(lockFile, lockFileTarget, dependencyLookup); - - ResourceAssembly[] resourceAssemblies = projectInfo - .ResourceAssemblies - .Select(r => new ResourceAssembly(r.RelativePath, r.Culture)) - .ToArray(); - - return new RuntimeLibrary( - type: "project", - name: projectInfo.Name, - version: projectInfo.Version, - hash: string.Empty, - runtimeAssemblyGroups: runtimeAssemblyGroups, - nativeLibraryGroups: new RuntimeAssetGroup[] { }, - resourceAssemblies: resourceAssemblies, - dependencies: dependencies.ToArray(), - serviceable: false); - } - - private CompilationLibrary GetProjectCompilationLibrary( - SingleProjectInfo projectInfo, - LockFile lockFile, - LockFileTarget lockFileTarget, - Dictionary dependencyLookup) - { - List dependencies = GetProjectDependencies(lockFile, lockFileTarget, dependencyLookup); - - return new CompilationLibrary( - type: "project", - name: projectInfo.Name, - version: projectInfo.Version, - hash: string.Empty, - assemblies: new[] { projectInfo.GetOutputName() }, - dependencies: dependencies.ToArray(), - serviceable: false); - } - - private IEnumerable GetLibraries( - IEnumerable exports, - IDictionary libraryLookup, - IDictionary dependencyLookup, - bool runtime) - { - return exports.Select(export => GetLibrary(export, libraryLookup, dependencyLookup, runtime)); - } - - private Library GetLibrary( - LockFileTargetLibrary export, - IDictionary libraryLookup, - IDictionary dependencyLookup, - bool runtime) - { - var type = export.Type; - - // TEMPORARY: All packages are serviceable in RC2 - // See https://github.com/dotnet/cli/issues/2569 - var serviceable = export.Type == "package"; - var libraryDependencies = new HashSet(); - - foreach (PackageDependency libraryDependency in export.Dependencies) - { - Dependency dependency; - if (dependencyLookup.TryGetValue(libraryDependency.Id, out dependency)) - { - libraryDependencies.Add(dependency); - } - } - - string hash = string.Empty; - string path = null; - string hashPath = null; - LockFileLibrary library; - if (libraryLookup.TryGetValue(export.Name, out library)) - { - if (!string.IsNullOrEmpty(library.Sha512)) - { - hash = "sha512-" + library.Sha512; - hashPath = _versionFolderPathResolver.GetHashFileName(export.Name, export.Version); - } - - path = library.Path; - } - - if (runtime) - { - return new RuntimeLibrary( - type.ToLowerInvariant(), - export.Name, - export.Version.ToString(), - hash, - CreateRuntimeAssemblyGroups(export), - CreateNativeLibraryGroups(export), - export.ResourceAssemblies.FilterPlaceHolderFiles().Select(CreateResourceAssembly), - libraryDependencies, - serviceable, - path, - hashPath); - } - else - { - IEnumerable assemblies = export - .CompileTimeAssemblies - .FilterPlaceHolderFiles() - .Select(libraryAsset => libraryAsset.Path); - - return new CompilationLibrary( - type.ToString().ToLowerInvariant(), - export.Name, - export.Version.ToString(), - hash, - assemblies, - libraryDependencies, - serviceable, - path, - hashPath); - } - } - - private IReadOnlyList CreateRuntimeAssemblyGroups(LockFileTargetLibrary export) - { - List assemblyGroups = new List(); - - assemblyGroups.Add( - new RuntimeAssetGroup( - string.Empty, - export.RuntimeAssemblies.FilterPlaceHolderFiles().Select(a => a.Path))); - - foreach (var runtimeTargetsGroup in export.GetRuntimeTargetsGroups("runtime")) - { - assemblyGroups.Add( - new RuntimeAssetGroup( - runtimeTargetsGroup.Key, - runtimeTargetsGroup.Select(t => t.Path))); - } - - return assemblyGroups; - } - - private IReadOnlyList CreateNativeLibraryGroups(LockFileTargetLibrary export) - { - List nativeGroups = new List(); - - nativeGroups.Add( - new RuntimeAssetGroup( - string.Empty, - export.NativeLibraries.FilterPlaceHolderFiles().Select(a => a.Path))); - - foreach (var runtimeTargetsGroup in export.GetRuntimeTargetsGroups("native")) - { - nativeGroups.Add( - new RuntimeAssetGroup( - runtimeTargetsGroup.Key, - runtimeTargetsGroup.Select(t => t.Path))); - } - - return nativeGroups; - } - - private ResourceAssembly CreateResourceAssembly(LockFileItem resourceAssembly) - { - string locale; - if (!resourceAssembly.Properties.TryGetValue("locale", out locale)) - { - locale = null; - } - - return new ResourceAssembly(resourceAssembly.Path, locale); - } - } -} diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs index 41688de82..6f20e15ac 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs @@ -326,9 +326,6 @@ namespace Microsoft.DotNet.Cli.Utils LocalizableStrings.GeneratingDepsJson, depsPath)); - var dependencyContext = new DepsJsonBuilder() - .Build(toolLibrary, null, toolLockFile, framework, null); - var tempDepsFile = Path.GetTempFileName(); var args = new List(); From d471037ce304133866526ae331b11da74fc1a1d9 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 26 Apr 2017 17:59:08 -0700 Subject: [PATCH 11/17] Show error if tools package doesn't include runtimeconfig file For test assets, don't explicitly include the runtimeconfig file, as the pack command does it automatically --- .../ToolWithOutputName/ToolWithOutputName.csproj | 6 ------ .../dotnet-dependency-context-test.csproj | 6 ------ .../dotnet-dependency-tool-invoker.csproj | 6 ------ .../dotnet-desktop-and-portable.csproj | 6 ------ .../dotnet-fallbackfoldertool.csproj | 7 +------ .../dotnet-outputsframeworkversion-netcoreapp1.0.csproj | 5 ----- .../dotnet-portable-v1-prefercli.csproj | 5 ----- .../dotnet-portable-v1/dotnet-portable-v1.csproj | 6 ------ .../TestPackages/dotnet-portable/dotnet-portable.csproj | 5 ----- .../dotnet-prefercliruntime.csproj | 4 ---- .../PackagedCommandSpecFactoryWithCliRuntime.cs | 8 ++++++++ src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs | 2 ++ 12 files changed, 11 insertions(+), 55 deletions(-) diff --git a/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj b/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj index 5639e3331..6c57ebe5d 100644 --- a/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj +++ b/TestAssets/TestPackages/ToolWithOutputName/ToolWithOutputName.csproj @@ -8,10 +8,4 @@ Exe - - - $(ProjectRuntimeConfigFilePath) - - - diff --git a/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj b/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj index 85afeaf74..97e20d00d 100644 --- a/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj +++ b/TestAssets/TestPackages/dotnet-dependency-context-test/dotnet-dependency-context-test.csproj @@ -7,12 +7,6 @@ Exe - - - $(ProjectRuntimeConfigFilePath) - - - diff --git a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj index 2ce9e3b1a..47539b5f0 100644 --- a/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj +++ b/TestAssets/TestPackages/dotnet-dependency-tool-invoker/dotnet-dependency-tool-invoker.csproj @@ -20,12 +20,6 @@ - - - $(ProjectRuntimeConfigFilePath) - - - diff --git a/TestAssets/TestPackages/dotnet-desktop-and-portable/dotnet-desktop-and-portable.csproj b/TestAssets/TestPackages/dotnet-desktop-and-portable/dotnet-desktop-and-portable.csproj index 1f3345bf4..185ef41f0 100644 --- a/TestAssets/TestPackages/dotnet-desktop-and-portable/dotnet-desktop-and-portable.csproj +++ b/TestAssets/TestPackages/dotnet-desktop-and-portable/dotnet-desktop-and-portable.csproj @@ -9,12 +9,6 @@ win7-x64;win7-x86 - - - $(ProjectRuntimeConfigFilePath) - - - 1.1.1 diff --git a/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj b/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj index 11aac9cf0..35e92a2bb 100644 --- a/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj +++ b/TestAssets/TestPackages/dotnet-fallbackfoldertool/dotnet-fallbackfoldertool.csproj @@ -7,10 +7,5 @@ Exe - - - - $(ProjectRuntimeConfigFilePath) - - + diff --git a/TestAssets/TestPackages/dotnet-outputsframeworkversion/dotnet-outputsframeworkversion-netcoreapp1.0/dotnet-outputsframeworkversion-netcoreapp1.0.csproj b/TestAssets/TestPackages/dotnet-outputsframeworkversion/dotnet-outputsframeworkversion-netcoreapp1.0/dotnet-outputsframeworkversion-netcoreapp1.0.csproj index 17c0af923..e26afd464 100644 --- a/TestAssets/TestPackages/dotnet-outputsframeworkversion/dotnet-outputsframeworkversion-netcoreapp1.0/dotnet-outputsframeworkversion-netcoreapp1.0.csproj +++ b/TestAssets/TestPackages/dotnet-outputsframeworkversion/dotnet-outputsframeworkversion-netcoreapp1.0/dotnet-outputsframeworkversion-netcoreapp1.0.csproj @@ -7,9 +7,4 @@ Exe 1.1.1 - - - $(ProjectRuntimeConfigFilePath) - - diff --git a/TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj b/TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj index 60ef7f71c..10cc9b117 100644 --- a/TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj +++ b/TestAssets/TestPackages/dotnet-portable-v1-prefercli/dotnet-portable-v1-prefercli.csproj @@ -14,10 +14,5 @@ - - - true - \prefercliruntime - diff --git a/TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj b/TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj index 3df959be1..b1bddfee9 100644 --- a/TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj +++ b/TestAssets/TestPackages/dotnet-portable-v1/dotnet-portable-v1.csproj @@ -6,12 +6,6 @@ Exe - - - $(ProjectRuntimeConfigFilePath) - - - diff --git a/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj b/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj index f8b581110..bc2925f73 100644 --- a/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj +++ b/TestAssets/TestPackages/dotnet-portable/dotnet-portable.csproj @@ -6,9 +6,4 @@ Exe - - - $(ProjectRuntimeConfigFilePath) - - diff --git a/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj b/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj index bd65e4cdd..21eb0a6d1 100644 --- a/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj +++ b/TestAssets/TestPackages/dotnet-prefercliruntime/dotnet-prefercliruntime.csproj @@ -8,10 +8,6 @@ - - $(ProjectRuntimeConfigFilePath) - - true \prefercliruntime diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs index 0d7edc4e3..c22af40ba 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactoryWithCliRuntime.cs @@ -22,6 +22,14 @@ namespace Microsoft.DotNet.Cli.Utils if(PrefersCliRuntime(commandPath)) { var runtimeConfigFile = Path.ChangeExtension(commandPath, FileNameSuffixes.RuntimeConfigJson); + + if (!File.Exists(runtimeConfigFile)) + { + throw new GracefulException(string.Format(LocalizableStrings.CouldNotFindToolRuntimeConfigFile, + nameof(PackagedCommandSpecFactory), + Path.GetFileName(commandPath))); + } + var runtimeConfig = new RuntimeConfig(runtimeConfigFile); var muxer = new Muxer(); diff --git a/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs b/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs index 455920e1b..3b2f17829 100644 --- a/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs +++ b/src/Microsoft.DotNet.Cli.Utils/LocalizableStrings.cs @@ -21,6 +21,8 @@ namespace Microsoft.DotNet.Cli.Utils public const string IgnoringPreferCLIRuntimeFile = "{0}: Ignoring prefercliruntime file as the tool target framework ({1}) has a different major version than the current CLI runtime ({2})"; + public const string CouldNotFindToolRuntimeConfigFile = "{0}: Could not find runtimeconfig.json file for tool {1}"; + public const string AttemptingToResolve = "{0}: attempting to resolve {1}"; public const string DidNotFindAMatchingProject = "{0}: Did not find a matching project {1}."; From 811bb94de8e3dcb9276268b42b2806032127dc51 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Wed, 26 Apr 2017 19:44:46 -0700 Subject: [PATCH 12/17] If generating deps.json fails, show MSBuild output in verbose output --- .../ProjectToolsCommandResolver.cs | 9 ++++-- .../ProcessStartInfoExtensions.cs | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs index 6f20e15ac..7cd9a6113 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs @@ -376,11 +376,16 @@ namespace Microsoft.DotNet.Cli.Utils Path.Combine(AppContext.BaseDirectory, "MSBuild.dll") : msBuildExePath; - var result = new MSBuildForwardingAppWithoutLogging(args, msBuildExePath).Execute(); + var result = new MSBuildForwardingAppWithoutLogging(args, msBuildExePath) + .GetProcessStartInfo() + .ExecuteAndCaptureOutput(out string stdOut, out string stdErr); if (result != 0) { - // TODO: Can / should we show the MSBuild output if there is a failure? + Reporter.Verbose.WriteLine(string.Format( + LocalizableStrings.UnableToGenerateDepsJson, + stdOut + Environment.NewLine + stdErr)); + throw new GracefulException(string.Format(LocalizableStrings.UnableToGenerateDepsJson, toolDepsJsonGeneratorProject)); } diff --git a/src/Microsoft.DotNet.Cli.Utils/ProcessStartInfoExtensions.cs b/src/Microsoft.DotNet.Cli.Utils/ProcessStartInfoExtensions.cs index 0805a7b41..0d11313b9 100644 --- a/src/Microsoft.DotNet.Cli.Utils/ProcessStartInfoExtensions.cs +++ b/src/Microsoft.DotNet.Cli.Utils/ProcessStartInfoExtensions.cs @@ -25,5 +25,36 @@ namespace Microsoft.DotNet.Cli.Utils return process.ExitCode; } + + public static int ExecuteAndCaptureOutput(this ProcessStartInfo startInfo, out string stdOut, out string stdErr) + { + var outStream = new StreamForwarder().Capture(); + var errStream = new StreamForwarder().Capture(); + + startInfo.RedirectStandardOutput = true; + startInfo.RedirectStandardError = true; + + var process = new Process + { + StartInfo = startInfo + }; + + process.EnableRaisingEvents = true; + + process.Start(); + + var taskOut = outStream.BeginRead(process.StandardOutput); + var taskErr = errStream.BeginRead(process.StandardError); + + process.WaitForExit(); + + taskOut.Wait(); + taskErr.Wait(); + + stdOut = outStream.CapturedOutput; + stdErr = errStream.CapturedOutput; + + return process.ExitCode; + } } } From 0c210b6e49491c97d92b47d2e84ff62cc8f8f1db Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 27 Apr 2017 09:27:06 -0700 Subject: [PATCH 13/17] Update to SDK version with support for tools deps file generation --- build/DependencyVersions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index d6500a942..99e55e6d9 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -4,7 +4,7 @@ 2.0.0-preview1-002091-00 15.2.0-preview-000093-02 2.0.0-rc4-61325-08 - 2.0.0-alpha-20170425-6 + 2.0.0-alpha-20170427-1 4.3.0-beta1-2418 1.0.0-rel-20170413-451 15.1.0-preview-20170414-04 From af9a85fd3f3b25a0a371527e3fe611fe184c2b75 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 27 Apr 2017 12:56:28 -0700 Subject: [PATCH 14/17] Disable multilevel lookup and fix tests that were depending on .NET Core 1.0 shared framework --- .../AppThrowingException/App/AppThrowingException.csproj | 2 +- run-build.ps1 | 3 +++ run-build.sh | 4 ++++ .../GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs | 1 - test/dotnet.Tests/PackagedCommandTests.cs | 2 -- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj b/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj index f595af9f3..6fede9c95 100644 --- a/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj +++ b/TestAssets/NonRestoredTestProjects/AppThrowingException/App/AppThrowingException.csproj @@ -3,7 +3,7 @@ Exe - netcoreapp1.0 + netcoreapp1.1 dotnet-throwingtool $(AssemblyName) diff --git a/run-build.ps1 b/run-build.ps1 index 12e7cb498..0c3ed5443 100644 --- a/run-build.ps1 +++ b/run-build.ps1 @@ -67,6 +67,9 @@ if (!(Test-Path $env:DOTNET_INSTALL_DIR)) # Disable first run since we want to control all package sources $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +# Don't resolve shared frameworks from user or global locations +$env:DOTNET_MULTILEVEL_LOOKUP=0 + # Enable vs test console logging $env:VSTEST_BUILD_TRACE=1 $env:VSTEST_TRACE_BUILD=1 diff --git a/run-build.sh b/run-build.sh index 801a14bc1..16cece2d1 100755 --- a/run-build.sh +++ b/run-build.sh @@ -151,6 +151,10 @@ export VSTEST_BUILD_TRACE=1 export VSTEST_TRACE_BUILD=1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 + +# Don't resolve shared frameworks from user or global locations +DOTNET_MULTILEVEL_LOOKUP=0 + toolsLocalPath="$REPOROOT/build_tools" if [ ! -z $BOOTSTRAP_INSTALL_DIR]; then toolsLocalPath = $BOOTSTRAP_INSTALL_DIR diff --git a/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs b/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs index 30ecc1f38..50b2879e6 100644 --- a/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs +++ b/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs @@ -14,7 +14,6 @@ namespace Microsoft.DotNet.Cli.Build.Tests public class GivenThatWeWantToBeBackwardsCompatibleWith1xProjects : TestBase { [Theory] - [InlineData("netcoreapp1.0")] [InlineData("netcoreapp1.1")] public void ItRestoresBuildsAndRuns(string target) { diff --git a/test/dotnet.Tests/PackagedCommandTests.cs b/test/dotnet.Tests/PackagedCommandTests.cs index e0f1cd2c5..bb75131d5 100644 --- a/test/dotnet.Tests/PackagedCommandTests.cs +++ b/test/dotnet.Tests/PackagedCommandTests.cs @@ -122,7 +122,6 @@ namespace Microsoft.DotNet.Tests new GenericCommand(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1") .WithWorkingDirectory(testInstance.Root) - .WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0") .Execute() .Should().Fail(); } @@ -159,7 +158,6 @@ namespace Microsoft.DotNet.Tests var result = new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes) .WithWorkingDirectory(testInstance.Root) - .WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0") .Execute(toolPrefersCLIRuntime ? "portable-v1-prefercli" : "portable-v1"); result.Should().Pass() From b972f8229e706757a7b60189917c8ac6d47fba9e Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 27 Apr 2017 13:45:12 -0700 Subject: [PATCH 15/17] Use backwards compatible runtimes for app throwing exception tests --- .../GivenAppThrowingException.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs index e5da522f8..0ce3550cb 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs @@ -28,9 +28,9 @@ namespace Microsoft.DotNet.Cli.Utils.Tests string msg1 = "Unhandled Exception: AppThrowing.MyException: " + "Exception of type 'AppThrowing.MyException' was thrown."; string msg2 = "at AppThrowing.MyException.Main(String[] args)"; - new RunCommand() + new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes) .WithWorkingDirectory(appRoot) - .ExecuteWithCapturedOutput() + .ExecuteWithCapturedOutput("run") .Should().Fail() .And.HaveStdErrContaining(msg1) .And.HaveStdErrContaining(msg2); @@ -67,7 +67,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests string msg1 = "Unhandled Exception: AppThrowing.MyException: " + "Exception of type 'AppThrowing.MyException' was thrown."; string msg2 = "at AppThrowing.MyException.Main(String[] args)"; - new DotnetCommand() + new DotnetCommand(DotnetUnderTest.WithBackwardsCompatibleRuntimes) .WithWorkingDirectory(appWithToolDepRoot) .ExecuteWithCapturedOutput("throwingtool") .Should().Fail() From fa2a02ff0efe0918c72f354b3f9886de4b66b93e Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 27 Apr 2017 13:52:48 -0700 Subject: [PATCH 16/17] Add metadata to test specifying required shared framework --- .../GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs b/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs index 50b2879e6..e41cf2c8e 100644 --- a/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs +++ b/test/dotnet-back-compat.Tests/GivenThatWeWantToBeBackwardsCompatibleWith1xProjects.cs @@ -13,7 +13,7 @@ namespace Microsoft.DotNet.Cli.Build.Tests { public class GivenThatWeWantToBeBackwardsCompatibleWith1xProjects : TestBase { - [Theory] + [RequiresSpecificFrameworkTheory("netcoreapp1.1")] [InlineData("netcoreapp1.1")] public void ItRestoresBuildsAndRuns(string target) { From b6d9520ffc1ffc600a072404b69caf929c37bcbd Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 27 Apr 2017 15:48:48 -0700 Subject: [PATCH 17/17] Fix tests that require .NET Core 1.1 --- .../GivenAppThrowingException.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs index 0ce3550cb..1470e6d78 100644 --- a/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs +++ b/test/Microsoft.DotNet.Cli.Utils.Tests/GivenAppThrowingException.cs @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests { public class GivenAppThrowingException : TestBase { - [Fact] + [RequiresSpecificFrameworkFact("netcoreapp1.1")] public void ItShowsStackTraceWhenRun() { var root = TestAssets.Get("NonRestoredTestProjects", "AppThrowingException") @@ -36,7 +36,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests .And.HaveStdErrContaining(msg2); } - [Fact] + [RequiresSpecificFrameworkFact("netcoreapp1.1")] public void ItShowsStackTraceWhenRunAsTool() { var root = TestAssets.Get("NonRestoredTestProjects", "AppThrowingException")