Skip to content

Commit 2e515f1

Browse files
committed
Add support for the SetParameters.xml file to override package configuration when publishing a webdeploy package to an azure website.
1 parent 09581f4 commit 2e515f1

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/ServiceManagement/Services/Commands.Test/Websites/PublishAzureWebsiteProjectTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void PublishFromPackage()
3434
Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();
3535

3636
clientMock.Setup(c => c.GetWebDeployPublishProfile(websiteName, slot)).Returns(publishProfile);
37-
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, connectionStrings, false, false))
37+
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, string.Empty, connectionStrings, false, false))
3838
.Callback((string n, string s, string p, Hashtable cs, bool skipAppData, bool doNotDelete) =>
3939
{
4040
Assert.Equal(websiteName, n);
@@ -93,7 +93,7 @@ public void PublishFromProjectFile()
9393

9494
clientMock.Setup(c => c.GetWebDeployPublishProfile(websiteName, slot)).Returns(publishProfile);
9595
clientMock.Setup(c => c.BuildWebProject(projectFile, configuration, logFile)).Returns(package);
96-
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, connectionStrings, false, false))
96+
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, string.Empty, connectionStrings, false, false))
9797
.Callback((string n, string s, string p, Hashtable cs, bool skipAppData, bool doNotDelete) =>
9898
{
9999
Assert.Equal(websiteName, n);

src/ServiceManagement/Services/Commands.Utilities/Websites/IWebsitesClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,11 @@ void EnableApplicationDiagnostic(
446446
/// <param name="websiteName">The name of the web site.</param>
447447
/// <param name="slot">The name of the slot.</param>
448448
/// <param name="package">The WebDeploy package.</param>
449+
/// <param name="setParametersFile">The SetParametersFile.xml used to override internal package configuration.</param>
449450
/// <param name="connectionStrings">The connection strings to overwrite the ones in the Web.config file.</param>
450451
/// <param name="skipAppData">Skip app data</param>
451452
/// <param name="doNotDelete">Do not delete files at destination</param>
452-
void PublishWebProject(string websiteName, string slot, string package, Hashtable connectionStrings, bool skipAppData, bool doNotDelete);
453+
void PublishWebProject(string websiteName, string slot, string package, string setParametersFile, Hashtable connectionStrings, bool skipAppData, bool doNotDelete);
453454

454455
/// <summary>
455456
/// Parse the Web.config files to get the connection string names.

src/ServiceManagement/Services/Commands.Utilities/Websites/WebsitesClient.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,18 +1212,19 @@ public WebSiteGetPublishProfileResponse.PublishProfile GetWebDeployPublishProfil
12121212
/// <param name="websiteName">The name of the web site.</param>
12131213
/// <param name="slot">The name of the slot.</param>
12141214
/// <param name="package">The WebDeploy package.</param>
1215+
/// <param name="setParametersFile">The SetParametersFile.xml used to override internal package configuration.</param>
12151216
/// <param name="connectionStrings">The connection strings to overwrite the ones in the Web.config file.</param>
12161217
/// <param name="skipAppData">Skip app data</param>
12171218
/// <param name="doNotDelete">Do not delete files at destination</param>
1218-
public void PublishWebProject(string websiteName, string slot, string package, Hashtable connectionStrings, bool skipAppData, bool doNotDelete)
1219+
public void PublishWebProject(string websiteName, string slot, string package, string setParametersFile, Hashtable connectionStrings, bool skipAppData, bool doNotDelete)
12191220
{
12201221
if (File.GetAttributes(package).HasFlag(FileAttributes.Directory))
12211222
{
12221223
PublishWebProjectFromPackagePath(websiteName, slot, package, connectionStrings, skipAppData, doNotDelete);
12231224
}
12241225
else
12251226
{
1226-
PublishWebProjectFromPackageFile(websiteName, slot, package, connectionStrings, skipAppData, doNotDelete);
1227+
PublishWebProjectFromPackageFile(websiteName, slot, package, setParametersFile, connectionStrings, skipAppData, doNotDelete);
12271228
}
12281229
}
12291230

@@ -1233,10 +1234,11 @@ public void PublishWebProject(string websiteName, string slot, string package, H
12331234
/// <param name="websiteName">The name of the web site.</param>
12341235
/// <param name="slot">The name of the slot.</param>
12351236
/// <param name="package">The WebDeploy package zip file.</param>
1237+
/// <param name="setParametersFile">The SetParametersFile.xml used to override internal package configuration.</param>
12361238
/// <param name="connectionStrings">The connection strings to overwrite the ones in the Web.config file.</param>
12371239
/// <param name="skipAppData">Skip app data</param>
12381240
/// <param name="doNotDelete">Do not delete files at destination</param>
1239-
private void PublishWebProjectFromPackageFile(string websiteName, string slot, string package, Hashtable connectionStrings, bool skipAppData, bool doNotDelete)
1241+
private void PublishWebProjectFromPackageFile(string websiteName, string slot, string package, string setParametersFile, Hashtable connectionStrings, bool skipAppData, bool doNotDelete)
12401242
{
12411243
DeploymentBaseOptions remoteBaseOptions = CreateRemoteDeploymentBaseOptions(websiteName, slot);
12421244
DeploymentBaseOptions localBaseOptions = new DeploymentBaseOptions();
@@ -1247,6 +1249,11 @@ private void PublishWebProjectFromPackageFile(string websiteName, string slot, s
12471249

12481250
using (var deployment = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Package, package, localBaseOptions))
12491251
{
1252+
if (!string.IsNullOrEmpty(setParametersFile))
1253+
{
1254+
deployment.SyncParameters.Load(setParametersFile, true);
1255+
}
1256+
12501257
DeploymentSyncParameter providerPathParameter = new DeploymentSyncParameter(
12511258
"Provider Path Parameter",
12521259
"Provider Path Parameter",
@@ -1264,8 +1271,9 @@ private void PublishWebProjectFromPackageFile(string websiteName, string slot, s
12641271
null);
12651272
providerPathParameter.Add(iisAppEntry);
12661273
providerPathParameter.Add(setAclEntry);
1267-
deployment.SyncParameters.Add(providerPathParameter);
12681274

1275+
deployment.SyncParameters.Add(providerPathParameter);
1276+
12691277
// Replace the connection strings in Web.config with the ones user specifies from the cmdlet.
12701278
ReplaceConnectionStrings(deployment, connectionStrings);
12711279

src/ServiceManagement/Services/Commands/Websites/PublishAzureWebsiteProject.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public class PublishAzureWebsiteProject : WebsiteContextBaseCmdlet, IDynamicPara
2828
[ValidateNotNullOrEmpty]
2929
public Hashtable ConnectionString { get; set; }
3030

31+
[Parameter(Mandatory = false, ParameterSetName = "Package", HelpMessage = "The WebDeploy SetParameters.xml file to transform configuration within the package.")]
32+
public string SetParametersFile { get; set; }
33+
3134
[Parameter(Mandatory = false, ParameterSetName = "ProjectFile")]
3235
[Parameter(Mandatory = false, ParameterSetName = "Package")]
3336
public SwitchParameter SkipAppData { get; set; }
@@ -40,6 +43,7 @@ public class PublishAzureWebsiteProject : WebsiteContextBaseCmdlet, IDynamicPara
4043
private string fullWebConfigFileWithConfiguration;
4144
private string fullWebConfigFile;
4245
private string fullPackage;
46+
private string fullSetParametersFile;
4347
private string configuration;
4448

4549
private RuntimeDefinedParameterDictionary dynamicParameters;
@@ -60,6 +64,8 @@ public override void ExecuteCmdlet()
6064
fullPackage = string.IsNullOrEmpty(fullPackage) ? this.TryResolvePath(Package) : fullPackage;
6165
WriteVerbose(string.Format(Resources.StartPublishingProjectTemplate, fullPackage));
6266

67+
fullSetParametersFile = string.IsNullOrEmpty(fullSetParametersFile) ? this.TryResolvePath(SetParametersFile) : fullSetParametersFile;
68+
6369
// Convert dynamic parameters to a connection string hash table.
6470
var connectionStrings = ConnectionString;
6571
if (connectionStrings == null)
@@ -80,7 +86,7 @@ public override void ExecuteCmdlet()
8086
try
8187
{
8288
// Publish the package.
83-
WebsitesClient.PublishWebProject(Name, Slot, fullPackage, connectionStrings, SkipAppData.IsPresent, DoNotDelete.IsPresent);
89+
WebsitesClient.PublishWebProject(Name, Slot, fullPackage, fullSetParametersFile, connectionStrings, SkipAppData.IsPresent, DoNotDelete.IsPresent);
8490
WriteVerbose(string.Format(Resources.CompletePublishingProjectTemplate, fullPackage));
8591
}
8692
catch (Exception)

0 commit comments

Comments
 (0)