-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Show a message when building as part of dotnet-run #12581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/Assets/TestProjects/TestAppWithLaunchSettings/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // 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; | ||
|
|
||
| namespace ConsoleApplication | ||
| { | ||
| public class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| Console.WriteLine("Hello world"); | ||
| Console.WriteLine($"MyCoolEnvironmentVariableKey={Environment.GetEnvironmentVariable("MyCoolEnvironmentVariableKey")}"); | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/Assets/TestProjects/TestAppWithLaunchSettings/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "profiles": { | ||
| "TestAppWithLaunchSettings": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": "true", | ||
| "environmentVariables": { | ||
| "MyCoolEnvironmentVariableKey": "MyCoolEnvironmentVariableValue" | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/Assets/TestProjects/TestAppWithLaunchSettings/TestAppWithLaunchSettings.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netcoreapp3.0</TargetFramework> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
src/Cli/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,21 @@ | ||
| // 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. | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Run.LaunchSettings | ||
| { | ||
| public class LaunchSettingsApplyResult | ||
| { | ||
| public LaunchSettingsApplyResult(bool success, string failureReason, string runAfterLaunch = null) | ||
| public LaunchSettingsApplyResult(bool success, string failureReason, ProjectLaunchSettingsModel launchSettings = null) | ||
| { | ||
| Success = success; | ||
| FailureReason = failureReason; | ||
| RunAfterLaunch = runAfterLaunch; | ||
| LaunchSettings = launchSettings; | ||
| } | ||
|
|
||
| public bool Success { get; } | ||
|
|
||
| public string FailureReason { get; } | ||
|
|
||
| public string RunAfterLaunch { get; } | ||
| public ProjectLaunchSettingsModel LaunchSettings { get; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Cli/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // 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; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Run.LaunchSettings | ||
| { | ||
| public class ProjectLaunchSettingsModel | ||
| { | ||
| public string CommandLineArgs { get; set; } | ||
|
|
||
| public bool LaunchBrowser { get; set; } | ||
|
|
||
| public string LaunchUrl { get; set; } | ||
|
|
||
| public string ApplicationUrl { get; set; } | ||
|
|
||
| public string DotNetRunMessages { get; set; } | ||
|
|
||
| public Dictionary<string, string> EnvironmentVariables { get; } = new Dictionary<string, string>(StringComparer.Ordinal); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,6 @@ | |
| using Microsoft.Build.Execution; | ||
| using Microsoft.Build.Exceptions; | ||
| using Microsoft.DotNet.Cli.Utils; | ||
| using Microsoft.DotNet.Tools; | ||
| using Microsoft.DotNet.Tools.MSBuild; | ||
| using Microsoft.DotNet.Tools.Run.LaunchSettings; | ||
| using Microsoft.DotNet.CommandFactory; | ||
|
|
||
|
|
@@ -41,17 +39,37 @@ public int Execute() | |
| { | ||
| Initialize(); | ||
|
|
||
| if (!TryGetLaunchProfileSettingsIfNeeded(out var launchSettings)) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| if (ShouldBuild) | ||
| { | ||
| if (string.Equals("true", launchSettings?.DotNetRunMessages, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| Reporter.Output.WriteLine(LocalizableStrings.RunCommandBuilding); | ||
| } | ||
|
|
||
| EnsureProjectIsBuilt(); | ||
| } | ||
|
|
||
| try | ||
| { | ||
| ICommand targetCommand = GetTargetCommand(); | ||
| if (!ApplyLaunchProfileSettingsIfNeeded(ref targetCommand)) | ||
| if (launchSettings != null) | ||
| { | ||
| return 1; | ||
| if (!string.IsNullOrEmpty(launchSettings.ApplicationUrl)) | ||
| { | ||
| targetCommand.EnvironmentVariable("ASPNETCORE_URLS", launchSettings.ApplicationUrl); | ||
| } | ||
|
|
||
| foreach (var entry in launchSettings.EnvironmentVariables) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no test coverage for this code |
||
| { | ||
| string value = Environment.ExpandEnvironmentVariables(entry.Value); | ||
| //NOTE: MSBuild variables are not expanded like they are in VS | ||
| targetCommand.EnvironmentVariable(entry.Key, value); | ||
| } | ||
| } | ||
|
|
||
| // Ignore Ctrl-C for the remainder of the command's execution | ||
|
|
@@ -92,8 +110,9 @@ public RunCommand(string configuration, | |
| Interactive = interactive; | ||
| } | ||
|
|
||
| private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand) | ||
| private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel launchSettingsModel) | ||
| { | ||
| launchSettingsModel = default; | ||
| if (!UseLaunchProfile) | ||
| { | ||
| return true; | ||
|
|
@@ -117,7 +136,8 @@ private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand) | |
|
|
||
| if (File.Exists(launchSettingsPath)) | ||
| { | ||
| if (!HasQuietVerbosity) { | ||
| if (!HasQuietVerbosity) | ||
| { | ||
| Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); | ||
| } | ||
|
|
||
|
|
@@ -126,11 +146,15 @@ private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand) | |
| try | ||
| { | ||
| var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); | ||
| var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref targetCommand, LaunchProfile); | ||
| var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, LaunchProfile); | ||
| if (!applyResult.Success) | ||
| { | ||
| Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red()); | ||
| } | ||
| else | ||
| { | ||
| launchSettingsModel = applyResult.LaunchSettings; | ||
| } | ||
| } | ||
| catch (IOException ex) | ||
| { | ||
|
|
@@ -155,7 +179,7 @@ private void EnsureProjectIsBuilt() | |
| new RestoringCommand( | ||
| restoreArgs.Prepend(Project), | ||
| restoreArgs, | ||
| new [] { Project }, | ||
| new[] { Project }, | ||
| NoRestore | ||
| ).Execute(); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no test coverage for this code