Allowing fallback to SiteName if PublishUrl isn't passed in for ZipDeploy profiles, to fix publish for ZipDeploy profiles created before 15.8 Preview 4.
This commit is contained in:
Родитель
02a50562b7
Коммит
980f876b54
|
@ -5,5 +5,6 @@
|
|||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
|
||||
#else
|
||||
[assembly: InternalsVisibleTo("Microsoft.NET.Sdk.Functions.Test")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.NET.Sdk.Functions.MSBuild.Tests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
#endif
|
||||
|
|
|
@ -61,6 +61,15 @@ namespace Microsoft.NET.Sdk.Functions.MSBuild.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Neither SiteName nor PublishUrl was given a value..
|
||||
/// </summary>
|
||||
internal static string NeitherSiteNameNorPublishUrlGivenError {
|
||||
get {
|
||||
return ResourceManager.GetString("NeitherSiteNameNorPublishUrlGivenError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Publishing {0} to {1}....
|
||||
/// </summary>
|
||||
|
|
|
@ -117,6 +117,9 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NeitherSiteNameNorPublishUrlGivenError" xml:space="preserve">
|
||||
<value>Neither SiteName nor PublishUrl was given a value.</value>
|
||||
</data>
|
||||
<data name="PublishingZipViaZipDeploy" xml:space="preserve">
|
||||
<value>Publishing {0} to {1}...</value>
|
||||
</data>
|
||||
|
|
|
@ -43,6 +43,7 @@ WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and
|
|||
ZipToPublishPath="$(ZippedPublishContentsPath)"
|
||||
DeploymentUsername="$(UserName)"
|
||||
DeploymentPassword="$(Password)"
|
||||
SiteName="$(DeployIisAppPath)"
|
||||
PublishUrl="$(PublishUrl)" />
|
||||
</Target>
|
||||
|
||||
|
|
|
@ -20,32 +20,51 @@ namespace Microsoft.NET.Sdk.Functions.Tasks
|
|||
[Required]
|
||||
public string DeploymentPassword { get; set; }
|
||||
|
||||
[Required]
|
||||
public string PublishUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Our fallback if PublishUrl is not given, which is the case for ZIP Deploy profiles created prior to 15.8 Preview 4.
|
||||
/// Using this will fail if the site is a slot.
|
||||
/// </summary>
|
||||
public string SiteName { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
using(DefaultHttpClient client = new DefaultHttpClient())
|
||||
{
|
||||
System.Threading.Tasks.Task<bool> t = ZipDeployAsync(ZipToPublishPath, DeploymentUsername, DeploymentPassword, PublishUrl, client);
|
||||
System.Threading.Tasks.Task<bool> t = ZipDeployAsync(ZipToPublishPath, DeploymentUsername, DeploymentPassword, PublishUrl, SiteName, client);
|
||||
t.Wait();
|
||||
return t.Result;
|
||||
}
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task<bool> ZipDeployAsync(string zipToPublishPath, string userName, string password, string publishUrl, IHttpClient client)
|
||||
internal async System.Threading.Tasks.Task<bool> ZipDeployAsync(string zipToPublishPath, string userName, string password, string publishUrl, string siteName, IHttpClient client)
|
||||
{
|
||||
if (!File.Exists(ZipToPublishPath) || client == null)
|
||||
if (!File.Exists(zipToPublishPath) || client == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!publishUrl.EndsWith("/"))
|
||||
{
|
||||
publishUrl += "/";
|
||||
}
|
||||
string zipDeployPublishUrl = null;
|
||||
|
||||
string zipDeployPublishUrl = publishUrl + "api/zipdeploy";
|
||||
if(!string.IsNullOrEmpty(publishUrl))
|
||||
{
|
||||
if (!publishUrl.EndsWith("/"))
|
||||
{
|
||||
publishUrl += "/";
|
||||
}
|
||||
|
||||
zipDeployPublishUrl = publishUrl + "api/zipdeploy";
|
||||
}
|
||||
else if(!string.IsNullOrEmpty(siteName))
|
||||
{
|
||||
zipDeployPublishUrl = $"https://{siteName}.scm.azurewebsites.net/api/zipdeploy";
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.LogError(Resources.NeitherSiteNameNorPublishUrlGivenError);
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.LogMessage(MessageImportance.High, String.Format(Resources.PublishingZipViaZipDeploy, zipToPublishPath, zipDeployPublishUrl));
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace ZipDeployPublish.Test
|
|||
Mock<IHttpClient> client = new Mock<IHttpClient>();
|
||||
ZipDeployTask zipDeployer = new ZipDeployTask();
|
||||
|
||||
bool result = await zipDeployer.ZipDeployAsync(string.Empty, "username", "password", "siteName", client.Object);
|
||||
bool result = await zipDeployer.ZipDeployAsync(string.Empty, "username", "password", "publishUrl", null, client.Object);
|
||||
|
||||
client.Verify(c => c.PostAsync(It.IsAny<Uri>(), It.IsAny<StreamContent>()), Times.Never);
|
||||
Assert.False(result);
|
||||
|
@ -77,7 +77,7 @@ namespace ZipDeployPublish.Test
|
|||
|
||||
ZipDeployTask zipDeployer = new ZipDeployTask();
|
||||
|
||||
bool result = await zipDeployer.ZipDeployAsync(TestZippedPublishContentsPath, "username", "password", "siteName", client.Object);
|
||||
bool result = await zipDeployer.ZipDeployAsync(TestZippedPublishContentsPath, "username", "password", "https://sitename.scm.azurewebsites.net", null, client.Object);
|
||||
|
||||
client.Verify(c => c.PostAsync(
|
||||
It.Is<Uri>(uri => string.Equals(uri.AbsoluteUri, "https://sitename.scm.azurewebsites.net/api/zipdeploy", StringComparison.Ordinal)),
|
||||
|
|
Загрузка…
Ссылка в новой задаче