Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Update launch settings for ApplicationUrl handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Lorbetske committed Mar 22, 2018
1 parent 56a56aa commit c1fff96
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<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>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeIdentifiers>win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;rhel.6-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64;alpine.3.6-x64</RuntimeIdentifiers>
</PropertyGroup>
</Project>
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 MSBuildTestApp
{
public class Program
{
public static void Main(string[] args)
{
var message = Environment.GetEnvironmentVariable("ASPNETCORE_URLS");
Console.WriteLine(message);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:49850/",
"sslPort": 0
}
},
"profiles": {
"First": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:12345/"
},
"applicationUrl": "http://localhost:67890/"
},
"Second": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:54321/"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public LaunchSettingsApplyResult TryApplySettings(JObject document, JObject mode
{
var config = model.ToObject<ProjectLaunchSettingsModel>();

if (!string.IsNullOrEmpty(config.ApplicationUrl))
{
command.EnvironmentVariable("ASPNETCORE_URLS", config.ApplicationUrl);
}

//For now, ignore everything but the environment variables section

foreach (var entry in config.EnvironmentVariables)
Expand All @@ -24,11 +29,6 @@ public LaunchSettingsApplyResult TryApplySettings(JObject document, JObject mode
command.EnvironmentVariable(entry.Key, value);
}

if (!string.IsNullOrEmpty(config.ApplicationUrl))
{
command.EnvironmentVariable("ASPNETCORE_URLS", config.ApplicationUrl);
}

return new LaunchSettingsApplyResult(true, null, config.LaunchUrl);
}

Expand Down
60 changes: 60 additions & 0 deletions test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,66 @@ public void ItDefaultsToTheFirstUsableLaunchProfile()
cmd.StdErr.Should().BeEmpty();
}

[Fact]
public void ItPrefersTheValueOfApplicationUrlFromEnvironmentVariablesOverTheProperty()
{
var testAppName = "AppWithApplicationUrlInLaunchSettings";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();

var testProjectDirectory = testInstance.Root.FullName;

new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("/p:SkipInvalidConfigurations=true")
.Should().Pass();

new BuildCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should().Pass();

var cmd = new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--launch-profile First");

cmd.Should().Pass()
.And.HaveStdOutContaining("http://localhost:12345/");

cmd.StdErr.Should().BeEmpty();
}

[Fact]
public void ItUsesTheValueOfApplicationUrlIfTheEnvironmentVariableIsNotSet()
{
var testAppName = "AppWithApplicationUrlInLaunchSettings";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();

var testProjectDirectory = testInstance.Root.FullName;

new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("/p:SkipInvalidConfigurations=true")
.Should().Pass();

new BuildCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should().Pass();

var cmd = new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("--launch-profile Second");

cmd.Should().Pass()
.And.HaveStdOutContaining("http://localhost:54321/");

cmd.StdErr.Should().BeEmpty();
}

[Fact]
public void ItGivesAnErrorWhenTheLaunchProfileNotFound()
{
Expand Down

0 comments on commit c1fff96

Please sign in to comment.