diff --git a/AzureIntegration.sln b/AzureIntegration.sln index f797b601f1..620c224223 100644 --- a/AzureIntegration.sln +++ b/AzureIntegration.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26401.1 +VisualStudioVersion = 15.0.26406.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.AzureAppServicesIntegration", "src\Microsoft.AspNetCore.AzureAppServicesIntegration\Microsoft.AspNetCore.AzureAppServicesIntegration.csproj", "{5916BEB5-0969-469B-976C-A392E015DFAC}" EndProject @@ -29,6 +29,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Applic EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationInsightsHostingStartupSample", "sample\ApplicationInsightsHostingStartupSample\ApplicationInsightsHostingStartupSample.csproj", "{33E245F0-2566-4B5B-BA7C-8895B7A697AE}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Web.Xdt.Extensions", "src\Microsoft.Web.Xdt.Extensions\Microsoft.Web.Xdt.Extensions.csproj", "{9B22E525-FEC9-4C7C-9F9C-598C15BD0250}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.AzureAppServices.SiteExtension", "src\Microsoft.AspNetCore.AzureAppServices.SiteExtension\Microsoft.AspNetCore.AzureAppServices.SiteExtension.csproj", "{1CE2D76B-39E6-46C0-8F6F-C63E370955A9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -63,6 +67,14 @@ Global {33E245F0-2566-4B5B-BA7C-8895B7A697AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {33E245F0-2566-4B5B-BA7C-8895B7A697AE}.Release|Any CPU.ActiveCfg = Release|Any CPU {33E245F0-2566-4B5B-BA7C-8895B7A697AE}.Release|Any CPU.Build.0 = Release|Any CPU + {9B22E525-FEC9-4C7C-9F9C-598C15BD0250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B22E525-FEC9-4C7C-9F9C-598C15BD0250}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B22E525-FEC9-4C7C-9F9C-598C15BD0250}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B22E525-FEC9-4C7C-9F9C-598C15BD0250}.Release|Any CPU.Build.0 = Release|Any CPU + {1CE2D76B-39E6-46C0-8F6F-C63E370955A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1CE2D76B-39E6-46C0-8F6F-C63E370955A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1CE2D76B-39E6-46C0-8F6F-C63E370955A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1CE2D76B-39E6-46C0-8F6F-C63E370955A9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -75,5 +87,7 @@ Global {939EA897-CA31-4F2E-BA51-22B570B64671} = {37237C93-6855-40D9-9E60-418B093EF49A} {2849A2D9-7C08-4198-BF2B-8BFB4B13554D} = {FF9B744E-6C59-40CC-9E41-9D2EBD292435} {33E245F0-2566-4B5B-BA7C-8895B7A697AE} = {37237C93-6855-40D9-9E60-418B093EF49A} + {9B22E525-FEC9-4C7C-9F9C-598C15BD0250} = {FF9B744E-6C59-40CC-9E41-9D2EBD292435} + {1CE2D76B-39E6-46C0-8F6F-C63E370955A9} = {FF9B744E-6C59-40CC-9E41-9D2EBD292435} EndGlobalSection EndGlobal diff --git a/NuGetPackageVerifier.json b/NuGetPackageVerifier.json index 1d9c164e0c..33addcaf71 100644 --- a/NuGetPackageVerifier.json +++ b/NuGetPackageVerifier.json @@ -4,7 +4,14 @@ "AdxVerificationCompositeRule" ], "packages": { - "Microsoft.AspNetCore.AzureAppServicesIntegration": { } + "Microsoft.AspNetCore.AzureAppServicesIntegration": { }, + "Microsoft.AspNetCore.AzureAppServices.SiteExtension": { + "Exclusions": { + "THIRDPARTY_DEPENDENCY_NOT_REGISTERED": { + "Microsoft.AspNetCore.AzureAppServices.SiteExtension; .NETFramework,Version=v4.5.1": "Microsoft.Web.Xdt.Extensions is locally developed and bundled into this package." + } + } + } } }, "Default": { // Rules to run for packages not listed in any other set. diff --git a/build/dependencies.props b/build/dependencies.props index 372da7f01e..8f5d72c7dc 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -8,6 +8,7 @@ 1.6.1 2.0.0-* 15.0.0 + 1.4.0 2.2.0 \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.AzureAppServices.SiteExtension/Microsoft.AspNetCore.AzureAppServices.SiteExtension.csproj b/src/Microsoft.AspNetCore.AzureAppServices.SiteExtension/Microsoft.AspNetCore.AzureAppServices.SiteExtension.csproj new file mode 100644 index 0000000000..05b733e99d --- /dev/null +++ b/src/Microsoft.AspNetCore.AzureAppServices.SiteExtension/Microsoft.AspNetCore.AzureAppServices.SiteExtension.csproj @@ -0,0 +1,24 @@ + + + + + + ASP.NET Core Extensions + This extension enables additional functionality for ASP.NET Core on Azure WebSites, such as enabling Azure logging. + net451 + false + aspnet;logging;aspnetcore + false + content + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.AzureAppServices.SiteExtension/applicationHost.xdt b/src/Microsoft.AspNetCore.AzureAppServices.SiteExtension/applicationHost.xdt new file mode 100644 index 0000000000..d7be87b14b --- /dev/null +++ b/src/Microsoft.AspNetCore.AzureAppServices.SiteExtension/applicationHost.xdt @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Microsoft.Web.Xdt.Extensions/InsertOrAppendAttribute.cs b/src/Microsoft.Web.Xdt.Extensions/InsertOrAppendAttribute.cs new file mode 100644 index 0000000000..26cb33338d --- /dev/null +++ b/src/Microsoft.Web.Xdt.Extensions/InsertOrAppendAttribute.cs @@ -0,0 +1,135 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Xml; +using Microsoft.Web.XmlTransform; + +namespace Microsoft.Web.Xdt.Extensions +{ + /// + /// Insert or append to the given attribute + /// + public class InsertOrAppendAttribute : Transform + { + /// + /// + /// + public InsertOrAppendAttribute() + : base(TransformFlags.UseParentAsTargetNode, MissingTargetMessage.Error) + { + } + + private string _attributeName; + + /// + /// + /// + protected string AttributeName + { + get + { + if (_attributeName == null) + { + _attributeName = GetArgumentValue("Attribute"); + } + return _attributeName; + } + } + + /// + /// Extracts a value from the arguments provided + /// + /// + /// + protected string GetArgumentValue(string name) + { + if (string.IsNullOrEmpty(name)) + { + throw new ArgumentNullException(nameof(name)); + } + + string result = null; + if (Arguments != null && Arguments.Count > 0) + { + foreach (var arg in Arguments) + { + if (!string.IsNullOrEmpty(arg)) + { + var trimmedArg = arg.Trim(); + if (trimmedArg.StartsWith(name, StringComparison.OrdinalIgnoreCase)) + { + var start = arg.IndexOf('\''); + var last = arg.LastIndexOf('\''); + if (start <= 0 || last <= 0 || last <= start) + { + throw new ArgumentException("Expected two ['] characters"); + } + + var value = trimmedArg.Substring(start, last - start); + + // remove any leading or trailing ' + value = value.Trim().TrimStart('\'').TrimStart('\''); + result = value; + } + } + } + } + return result; + } + + /// + /// + /// + protected override void Apply() + { + if (TargetChildNodes == null || TargetChildNodes.Count == 0) + { + TargetNode.AppendChild(TransformNode); + } + else + { + XmlAttribute transformAtt = null; + + foreach (XmlAttribute att in TransformNode.Attributes) + { + if (string.Equals(att.Name, AttributeName, StringComparison.OrdinalIgnoreCase)) + { + transformAtt = att; + break; + } + } + + if (transformAtt == null) + { + throw new InvalidOperationException("No target attribute to append"); + } + + foreach (XmlNode targetNode in TargetChildNodes) + { + foreach (XmlAttribute att in targetNode.Attributes) + { + if (string.Equals(att.Name, AttributeName, StringComparison.OrdinalIgnoreCase)) + { + if (string.IsNullOrEmpty(att.Value)) + { + att.Value = transformAtt.Value; + } + else + { + // TODO: This doesn't compose well with insertOrAppend being applied on the TargetNode. + // The target node is created with the children it has in the transform, which means we would + // duplicate the value here. + if (att.Value == transformAtt.Value) + { + return; + } + att.Value = $"{att.Value};{transformAtt.Value}"; + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.Web.Xdt.Extensions/Microsoft.Web.Xdt.Extensions.csproj b/src/Microsoft.Web.Xdt.Extensions/Microsoft.Web.Xdt.Extensions.csproj new file mode 100644 index 0000000000..0e7af07f4b --- /dev/null +++ b/src/Microsoft.Web.Xdt.Extensions/Microsoft.Web.Xdt.Extensions.csproj @@ -0,0 +1,16 @@ + + + + + + Additional functionality for Xdt transforms. + net451 + true + xdt + + + + + + + \ No newline at end of file