0

我正在尝试将以下 WORKING 命令行转换为 web deploy api (Microsoft.Web.Deployment) 代码:

"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:contentPath="\\myserver\code_to_deploy" -dest:contentPath="Default Web Site",wmsvc="mysandbox",userName="MyWebDeployUser",password="MyPassword" -allowUntrusted

我的样子是这样的:

string srcPath = "\\myserver\code_to_deploy";
string destPath = "Default Web Site";

DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions();
sourceOptions.TraceLevel = TraceLevel.Verbose;          
sourceOptions.Trace += new EventHandler<DeploymentTraceEventArgs>(Src_Trace);

DeploymentBaseOptions destOptions = new DeploymentBaseOptions();            
destOptions.UserName = "MyWebDeployUser";
destOptions.Password = "MyPassword";
destOptions.AddDefaultProviderSetting("contentPath", "wmsvc", "mysandbox");         
destOptions.AuthenticationType = "basic";

destOptions.TraceLevel = TraceLevel.Verbose;
destOptions.Trace += new EventHandler<DeploymentTraceEventArgs>(Dest_Trace);

ServicePointManager.ServerCertificateValidationCallback = (s, c, chain, err) =>
{
    return true;
};          
DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
syncOptions.DeleteDestination = true;

using (DeploymentObject depObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, srcPath, sourceOptions))
{               
    var summary = depObj.SyncTo(DeploymentWellKnownProvider.IisApp, destPath, destOptions, syncOptions);
}

当代码调用“AddDefaultProviderSetting”时,它会失败,说明提供程序不支持 wmsvc。如果我删除该行,我会从服务器收到 401。非常感谢任何这样做或其他帮助的例子。

4

1 回答 1

0

我不知道您是否找到了解决方案,但这里有一个代码片段,允许需要它的人使用 wmsvc:

        DeploymentBaseOptions destinationOptions = new DeploymentBaseOptions()
        {
            UserName = "<user_name>",
            Password = "<password>",
            IncludeAcls = false,
            AuthenticationType = "Basic",
            UseDelegation = true,
            ComputerName = "https://<server>:8172/msdeploy.axd?Site=<website>"
        };

       // Use -allowUntrusted option
       ServicePointManager.ServerCertificateValidationCallback +=
            new RemoteCertificateValidationCallback(
                (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => { return true; });

       string package = <zip_package_fullPath>;
       string parameters = <project_SetParameters_xml_fullPath>;
       using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Package, package))
        {
            deploymentObject.SyncParameters.Load(parameters);
            DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();

            DeploymentChangeSummary results = deploymentObject.SyncTo(destinationOptions, syncOptions);
        }

很难找到有关这些主题的文档。顺便说一句,即使通过创建 .exe.configSettings 文件,我也没有成功使用 AddDefaultProviderSetting,我不确定这是实现您想要的正确方法。

要创建虚拟应用程序而不是网站,只需将 .SetParameters.xml 从

<setParameter name="IIS Web Application Name" value="<WebSite>" />

<setParameter name="IIS Web Application Name" value="<WebSite>/<VirtualApp>" />

希望这可以帮助。

于 2013-11-27T15:17:20.700 回答