Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<PropertyGroup>
<_IsAspNetCoreProject Condition="%(ProjectCapability.Identity) == 'AspNetCore'">true</_IsAspNetCoreProject>
<_IsPortable Condition=" '$(_IsPortable)' == '' And '$(SelfContained)' == 'true' ">false</_IsPortable>
<_IsPortable Condition=" '$(_IsPortable)' == ''">true</_IsPortable>
<_UseAppHost Condition=" '$(_UseAppHost)' == '' ">$(UseAppHost)</_UseAppHost>
<_UseAppHost Condition=" '$(_UseAppHost)' == ''">$(SelfContained)</_UseAppHost>
<_UseAppHost Condition=" '$(_UseAppHost)' == ''">false</_UseAppHost>
<_ExecutableExtension Condition="'$(_ExecutableExtension)' == '' and $(RuntimeIdentifier.StartsWith('win'))">.exe</_ExecutableExtension>
<_TransformWebConfigForAzure Condition=" '$(WEBSITE_SITE_NAME)' != '' Or '$(DOTNET_CONFIGURE_AZURE)' == 'true' Or '$(DOTNET_CONFIGURE_AZURE)' == '1'">true</_TransformWebConfigForAzure>
<_TransformWebConfigForAzure Condition=" '$(PublishProvider)' == 'AzureWebSite' Or '$(WEBSITE_SITE_NAME)' != '' Or '$(DOTNET_CONFIGURE_AZURE)' == 'true' Or '$(DOTNET_CONFIGURE_AZURE)' == '1'">true</_TransformWebConfigForAzure>
</PropertyGroup>


<TransformWebConfig
Condition="'$(_IsAspNetCoreProject)' == 'true' And '$(IsTransformWebConfigDisabled)' != 'true' And '$(IsWebConfigTransformDisabled)' != 'true'"
TargetPath="$(TargetPath)"
PublishDir="$(PublishIntermediateOutputPath)"
IsPortable="$(_IsPortable)"
UseAppHost="$(UseAppHost)"
ExecutableExtension="$(_ExecutableExtension)"
IsAzure="$(_TransformWebConfigForAzure)"
ProjectGuid="$(ProjectGuid)"
Expand Down Expand Up @@ -112,8 +113,9 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<PropertyGroup>
<_IsWebJobProject Condition="'$(_IsWebJobProject)' == '' and '$(WebJobName)' != '' and '$(WebJobType)' != ''">true</_IsWebJobProject>
<_IsPortable Condition=" '$(_IsPortable)' == '' And '$(RuntimeIdentifier)' != '' ">false</_IsPortable>
<_IsPortable Condition=" '$(_IsPortable)' == ''">true</_IsPortable>
<_UseAppHost Condition=" '$(_UseAppHost)' == '' ">$(UseAppHost)</_UseAppHost>
<_UseAppHost Condition=" '$(_UseAppHost)' == '' ">$(SelfContained)</_UseAppHost>
<_UseAppHost Condition=" '$(_UseAppHost)' == '' ">false</_UseAppHost>
<_ExecutableExtension Condition="'$(_ExecutableExtension)' == '' and $(RuntimeIdentifier.StartsWith('win'))">.exe</_ExecutableExtension>
</PropertyGroup>

Expand All @@ -122,7 +124,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
ProjectDirectory="$(MSBuildProjectDirectory)"
TargetPath="$(TargetPath)"
WebJobsDirectory="$(PublishIntermediateOutputPath)\app_data\Jobs\$(WebJobType)\$(WebJobName)\"
IsPortable="$(_IsPortable)"
UseAppHost="$(_UseAppHost)"
ExecutableExtension="$(_ExecutableExtension)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ public class TransformWebConfig : Task
[Required]
public string PublishDir { get; set; }

/// <summary>
/// The application being published is a portable .NET Core application
/// </summary>
/// <returns></returns>
[Required]
public bool IsPortable { get; set; }
public bool UseAppHost { get; set; }

/// <summary>
/// [optional] Transform is targeted for Azure
Expand Down Expand Up @@ -89,7 +85,7 @@ public override bool Execute()
}

string outputFile = Path.GetFileName(TargetPath);
XDocument transformedConfig = WebConfigTransform.Transform(webConfigXml, outputFile, IsAzure, IsPortable, ExecutableExtension, AspNetCoreModuleHostingModel);
XDocument transformedConfig = WebConfigTransform.Transform(webConfigXml, outputFile, IsAzure, UseAppHost, ExecutableExtension, AspNetCoreModuleHostingModel);

// Telemetry
transformedConfig = WebConfigTelemetry.AddTelemetry(transformedConfig, ProjectGuid, IgnoreProjectGuid, SolutionPath, ProjectFullPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

Expand All @@ -14,7 +15,7 @@ public class GenerateRunCommandFile : Task
[Required]
public string TargetPath { get; set; }
[Required]
public bool IsPortable { get; set; }
public bool UseAppHost { get; set; }
public string ExecutableExtension { get; set; }

public override bool Execute()
Expand All @@ -23,8 +24,9 @@ public override bool Execute()
if (!isRunCommandFilePresent)
{
string appName = Path.GetFileName(TargetPath);

string command = $"dotnet {appName}";
if (!IsPortable)
if (UseAppHost || string.Equals(Path.GetExtension(TargetPath), ".exe", StringComparison.OrdinalIgnoreCase))
{
command = Path.ChangeExtension(appName, !string.IsNullOrWhiteSpace(ExecutableExtension) ? ExecutableExtension : null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.NET.Sdk.Publish.Tasks
{
public static class WebConfigTransform
{
public static XDocument Transform(XDocument webConfig, string appName, bool configureForAzure, bool isPortable, string extension, string aspNetCoreHostingModel)
public static XDocument Transform(XDocument webConfig, string appName, bool configureForAzure, bool useAppHost, string extension, string aspNetCoreHostingModel)
{
const string HandlersElementName = "handlers";
const string aspNetCoreElementName = "aspNetCore";
Expand All @@ -22,7 +22,7 @@ public static XDocument Transform(XDocument webConfig, string appName, bool conf
var webServerSection = GetOrCreateChild(webConfig.Root, "system.webServer");

TransformHandlers(GetOrCreateChild(webServerSection, HandlersElementName));
TransformAspNetCore(GetOrCreateChild(webServerSection, aspNetCoreElementName), appName, configureForAzure, isPortable, extension, aspNetCoreHostingModel);
TransformAspNetCore(GetOrCreateChild(webServerSection, aspNetCoreElementName), appName, configureForAzure, useAppHost, extension, aspNetCoreHostingModel);

// make sure that the aspNetCore element is after handlers element
var aspNetCoreElement = webServerSection.Element(HandlersElementName)
Expand Down Expand Up @@ -55,21 +55,16 @@ private static void TransformHandlers(XElement handlersElement)
SetAttributeValueIfEmpty(aspNetCoreElement, "resourceType", "Unspecified");
}

private static void TransformAspNetCore(XElement aspNetCoreElement, string appName, bool configureForAzure, bool isPortable, string extension, string aspNetCoreHostingModel)
private static void TransformAspNetCore(XElement aspNetCoreElement, string appName, bool configureForAzure, bool useAppHost, string extension, string aspNetCoreHostingModel)
{
// Forward slashes currently work neither in AspNetCoreModule nor in dotnet so they need to be
// replaced with backwards slashes when the application is published on a non-Windows machine
var appPath = Path.Combine(".", appName).Replace("/", "\\");
var originalExtension = Path.GetExtension(appPath);
RemoveLauncherArgs(aspNetCoreElement);

if (!isPortable)
if (useAppHost || string.Equals(Path.GetExtension(appPath), ".exe", StringComparison.OrdinalIgnoreCase))
{
appPath = Path.ChangeExtension(appPath, !string.IsNullOrWhiteSpace(extension) ? extension : null);
}

if (!isPortable || string.Equals(originalExtension, ".exe", StringComparison.OrdinalIgnoreCase))
{
aspNetCoreElement.SetAttributeValue("processPath", appPath);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void WebConfigTransform_Finds_ProjectGuid_IfProjectPathIsPassed(string so
public void WebConfigTelemetry_SetsProjectGuidIfNotOptedOut(string projectGuid)
{
// Arrange
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, isPortable: false, extension:".exe", aspNetCoreHostingModel:null);
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, useAppHost: true, extension:".exe", aspNetCoreHostingModel:null);
Assert.True(XNode.DeepEquals(WebConfigTemplate, transformedWebConfig));

//Act
Expand All @@ -81,7 +81,7 @@ public void WebConfigTelemetry_SetsProjectGuidIfNotOptedOut(string projectGuid)
public void WebConfigTelemetry_DoesNotSetProjectGuidIfOptedOut_ThroughIgnoreProjectGuid(string projectGuid)
{
// Arrange
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, isPortable: false, extension: ".exe", aspNetCoreHostingModel:null);
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, useAppHost: true, extension: ".exe", aspNetCoreHostingModel:null);
Assert.True(XNode.DeepEquals(WebConfigTemplate, transformedWebConfig));

//Act
Expand All @@ -96,7 +96,7 @@ public void WebConfigTelemetry_DoesNotSetProjectGuidIfOptedOut_ThroughIgnoreProj
public void WebConfigTelemetry_RemovesProjectGuidIfOptedOut_ThroughIgnoreProjectGuid(string projectGuid)
{
// Arrange
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, isPortable: false, extension: ".exe", aspNetCoreHostingModel:null);
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, useAppHost: true, extension: ".exe", aspNetCoreHostingModel:null);
Assert.True(XNode.DeepEquals(WebConfigTemplate, transformedWebConfig));
// Adds Guid to the config
XDocument transformedWebConfigWithGuid = WebConfigTelemetry.AddTelemetry(transformedWebConfig, projectGuid, false, null, null);
Expand All @@ -116,7 +116,7 @@ public void WebConfigTelemetry_FindsProjectGuid_IfCLIOptedOutEnvVariableIsNotSet
{
// Arrange
string projectFullPath = GetTestProjectsFullPath();
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, isPortable: false, extension: ".exe", aspNetCoreHostingModel: null);
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, useAppHost: true, extension: ".exe", aspNetCoreHostingModel: null);
string previousValue = Environment.GetEnvironmentVariable(TelemetryOptout);

//Act
Expand All @@ -135,7 +135,7 @@ public void WebConfigTelemetry_DoesNotSearchForProjectGuid_IfCLIOptedOutEnvVaria
{
// Arrange
string projectFullPath = GetTestProjectsFullPath();
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, isPortable: false, extension: ".exe", aspNetCoreHostingModel: null);
XDocument transformedWebConfig = WebConfigTransform.Transform(null, "test.exe", configureForAzure: false, useAppHost: true, extension: ".exe", aspNetCoreHostingModel: null);
string previousValue = Environment.GetEnvironmentVariable(TelemetryOptout);

//Act
Expand Down
Loading