Skip to content
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 @@ -23,6 +23,7 @@ public void PublishFromPackage()
var package = "test-package";
var connectionStrings = new Hashtable();
connectionStrings["DefaultConnection"] = "test-connection-string";
string setParametersFile = "testfile.xml";

var publishProfile = new WebSiteGetPublishProfileResponse.PublishProfile()
{
Expand All @@ -36,12 +37,13 @@ public void PublishFromPackage()
Mock<IWebsitesClient> clientMock = new Mock<IWebsitesClient>();

clientMock.Setup(c => c.GetWebDeployPublishProfile(websiteName, slot)).Returns(publishProfile);
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, connectionStrings, false, false))
.Callback((string n, string s, string p, Hashtable cs, bool skipAppData, bool doNotDelete) =>
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, setParametersFile, connectionStrings, false, false))
.Callback((string n, string s, string p, string spf, Hashtable cs, bool skipAppData, bool doNotDelete) =>
{
Assert.Equal(websiteName, n);
Assert.Equal(slot, s);
Assert.Equal(package, p);
Assert.Equal(setParametersFile, spf);
Assert.Equal(connectionStrings, cs);
Assert.False(skipAppData);
Assert.False(doNotDelete);
Expand All @@ -56,7 +58,8 @@ public void PublishFromPackage()
Name = websiteName,
Package = package,
ConnectionString = connectionStrings,
WebsitesClient = clientMock.Object
WebsitesClient = clientMock.Object,
SetParametersFile = setParametersFile
};

command.ExecuteCmdlet();
Expand All @@ -76,6 +79,7 @@ public void PublishFromProjectFile()
var logFile = string.Format(@"{0}\build.log", Directory.GetCurrentDirectory());
var connectionStrings = new Hashtable();
connectionStrings["DefaultConnection"] = "test-connection-string";
string setParametersFile = "testfile.xml";

using (FileSystemHelper files = new FileSystemHelper(this))
{
Expand All @@ -96,12 +100,13 @@ public void PublishFromProjectFile()

clientMock.Setup(c => c.GetWebDeployPublishProfile(websiteName, slot)).Returns(publishProfile);
clientMock.Setup(c => c.BuildWebProject(projectFile, configuration, logFile)).Returns(package);
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, connectionStrings, false, false))
.Callback((string n, string s, string p, Hashtable cs, bool skipAppData, bool doNotDelete) =>
clientMock.Setup(c => c.PublishWebProject(websiteName, slot, package, setParametersFile, connectionStrings, false, false))
.Callback((string n, string s, string p, string spf, Hashtable cs, bool skipAppData, bool doNotDelete) =>
{
Assert.Equal(websiteName, n);
Assert.Equal(slot, s);
Assert.Equal(package, p);
Assert.Equal(setParametersFile, spf);
Assert.Equal(connectionStrings, cs);
Assert.False(skipAppData);
Assert.False(doNotDelete);
Expand All @@ -117,7 +122,8 @@ public void PublishFromProjectFile()
Name = websiteName,
ProjectFile = projectFile,
Configuration = configuration,
ConnectionString = connectionStrings
ConnectionString = connectionStrings,
SetParametersFile = setParametersFile
};

command.ExecuteCmdlet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,11 @@ void EnableApplicationDiagnostic(
/// <param name="websiteName">The name of the web site.</param>
/// <param name="slot">The name of the slot.</param>
/// <param name="package">The WebDeploy package.</param>
/// <param name="setParametersFile">The SetParametersFile.xml used to override internal package configuration.</param>
/// <param name="connectionStrings">The connection strings to overwrite the ones in the Web.config file.</param>
/// <param name="skipAppData">Skip app data</param>
/// <param name="doNotDelete">Do not delete files at destination</param>
void PublishWebProject(string websiteName, string slot, string package, Hashtable connectionStrings, bool skipAppData, bool doNotDelete);
void PublishWebProject(string websiteName, string slot, string package, string setParametersFile, Hashtable connectionStrings, bool skipAppData, bool doNotDelete);

/// <summary>
/// Parse the Web.config files to get the connection string names.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,18 +1212,19 @@ public WebSiteGetPublishProfileResponse.PublishProfile GetWebDeployPublishProfil
/// <param name="websiteName">The name of the web site.</param>
/// <param name="slot">The name of the slot.</param>
/// <param name="package">The WebDeploy package.</param>
/// <param name="setParametersFile">The SetParametersFile.xml used to override internal package configuration.</param>
/// <param name="connectionStrings">The connection strings to overwrite the ones in the Web.config file.</param>
/// <param name="skipAppData">Skip app data</param>
/// <param name="doNotDelete">Do not delete files at destination</param>
public void PublishWebProject(string websiteName, string slot, string package, Hashtable connectionStrings, bool skipAppData, bool doNotDelete)
public void PublishWebProject(string websiteName, string slot, string package, string setParametersFile, Hashtable connectionStrings, bool skipAppData, bool doNotDelete)
{
if (File.GetAttributes(package).HasFlag(FileAttributes.Directory))
{
PublishWebProjectFromPackagePath(websiteName, slot, package, connectionStrings, skipAppData, doNotDelete);
}
else
{
PublishWebProjectFromPackageFile(websiteName, slot, package, connectionStrings, skipAppData, doNotDelete);
PublishWebProjectFromPackageFile(websiteName, slot, package, setParametersFile, connectionStrings, skipAppData, doNotDelete);
}
}

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

using (var deployment = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Package, package, localBaseOptions))
{
if (!string.IsNullOrEmpty(setParametersFile))
{
deployment.SyncParameters.Load(setParametersFile, true);
}

DeploymentSyncParameter providerPathParameter = new DeploymentSyncParameter(
"Provider Path Parameter",
"Provider Path Parameter",
Expand All @@ -1264,8 +1271,9 @@ private void PublishWebProjectFromPackageFile(string websiteName, string slot, s
null);
providerPathParameter.Add(iisAppEntry);
providerPathParameter.Add(setAclEntry);
deployment.SyncParameters.Add(providerPathParameter);

deployment.SyncParameters.Add(providerPathParameter);

// Replace the connection strings in Web.config with the ones user specifies from the cmdlet.
ReplaceConnectionStrings(deployment, connectionStrings);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class PublishAzureWebsiteProject : WebsiteContextBaseCmdlet, IDynamicPara
[ValidateNotNullOrEmpty]
public Hashtable ConnectionString { get; set; }

[Parameter(Mandatory = false, ParameterSetName = "Package", HelpMessage = "The WebDeploy SetParameters.xml file to transform configuration within the package.")]
public string SetParametersFile { get; set; }

[Parameter(Mandatory = false, ParameterSetName = "ProjectFile")]
[Parameter(Mandatory = false, ParameterSetName = "Package")]
public SwitchParameter SkipAppData { get; set; }
Expand All @@ -40,6 +43,7 @@ public class PublishAzureWebsiteProject : WebsiteContextBaseCmdlet, IDynamicPara
private string fullWebConfigFileWithConfiguration;
private string fullWebConfigFile;
private string fullPackage;
private string fullSetParametersFile;
private string configuration;

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

fullSetParametersFile = string.IsNullOrEmpty(fullSetParametersFile) ? this.TryResolvePath(SetParametersFile) : fullSetParametersFile;

// Convert dynamic parameters to a connection string hash table.
var connectionStrings = ConnectionString;
if (connectionStrings == null)
Expand All @@ -80,7 +86,7 @@ public override void ExecuteCmdlet()
try
{
// Publish the package.
WebsitesClient.PublishWebProject(Name, Slot, fullPackage, connectionStrings, SkipAppData.IsPresent, DoNotDelete.IsPresent);
WebsitesClient.PublishWebProject(Name, Slot, fullPackage, fullSetParametersFile, connectionStrings, SkipAppData.IsPresent, DoNotDelete.IsPresent);
WriteVerbose(string.Format(Resources.CompletePublishingProjectTemplate, fullPackage));
}
catch (Exception)
Expand Down