我们如何在共享主机上从 TFS 部署到 IIS? (去吧爸爸)

How can we deploy from TFS to IIS on shared hosting? (GoDaddy)

找到的文档 here 描述了如何部署到 IIS,但 WinRM 组件需要本地管理员权限。显然,这不适用于与 GoDaddy 等服务提供商共享的主机。 (出于本次讨论的目的,我们将排除 Azure 目标。)

Visual Studio 可以很容易地做到这一点,只需使用导入的 .publishsettings 文件即可。难道 TFS 不需要额外权限就应该能够做同样的事情吗?

...或者我们在尝试使用 TFS 发布到非 Azure 共享主机配置时只是运气不好?

--编辑--

我整天都在研究 Patrick 的建议答案,经过无数次配置组合后,我仍然一无所获。 MSBuild 看起来确实是解决此问题的方法,是的,但我无法在我的 TFS 2018 上使用它。

发布任务的输出如下。如我们所见,MSBuild 拒绝将站点发布到我的本地测试 IIS。

奇怪的是,当我 运行 从我本地工作站上的命令 window 下面的日志中的命令(在调整相关文件后)时, MSBuild 按预期发布路径,当然,并删除 /dl:CentralLogger 开关)。

我尝试的其中一件事是 edit/delete source/target 上的文件,以尝试强制同步。那也没用。

有没有人看出这不起作用的任何迹象?

日志

2018-02-27T04:48:38.4708105Z ##[section]Starting: Build solution $(System.DefaultWorkingDirectory)/Website/drop/Website.vbproj
2018-02-27T04:48:38.4938123Z ==============================================================================
2018-02-27T04:48:38.4938123Z Task         : Visual Studio Build
2018-02-27T04:48:38.4938123Z Description  : Build with MSBuild and set the Visual Studio version property
2018-02-27T04:48:38.4938123Z Version      : 1.120.0
2018-02-27T04:48:38.4938123Z Author       : Microsoft Corporation
2018-02-27T04:48:38.4938123Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613727)
2018-02-27T04:48:38.4938123Z ==============================================================================
2018-02-27T04:48:41.0024890Z ##[command]"D:\Agent\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.120.0\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
2018-02-27T04:48:41.7115427Z ##[command]"C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild.0\Bin\msbuild.exe" "D:\Agent\_work\r5\a\Website\drop\Website.vbproj" /nologo /nr:false /dl:CentralLogger,"D:\Agent\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.120.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=6e6502d0-9bea-46af-a5a7-9dac551b9e29|SolutionDir=D:\Agent\_work\r5\a\Website\drop"*ForwardingLogger,"D:\Agent\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda.120.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:DeployOnBuild=true /p:AllowUntrustedCertificate=true /p:PublishProfile="D:\Agent\_work\r5\a\Website\drop\My Project\PublishProfiles\QA.pubxml" /p:Password=******** /p:platform="AnyCPU" /p:configuration="release" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="TFS_1c911c00-1ecd-4ca9-87b0-d8d34f8c59c4_release_2_24_24_1"
2018-02-27T04:48:42.3456044Z Build started 2/26/2018 7:48:42 PM.
2018-02-27T04:48:44.0457237Z Project "D:\Agent\_work\r5\a\Website\drop\Website.vbproj" on node 1 (default targets).
2018-02-27T04:48:44.0487239Z CoreResGen:
2018-02-27T04:48:44.0487239Z   No resources are out of date with respect to their source files. Skipping resource generation.
2018-02-27T04:48:44.2587401Z CoreCompile:
2018-02-27T04:48:44.2597397Z   C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild.0\Bin\Roslyn\vbc.exe /noconfig /imports:Intexx,Intexx.Linq,Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.ComponentModel,System.Data,System.Data.Common,System.Data.Entity,System.Data.Entity.Migrations,System.Data.SqlClient,System.IO,System.Linq,System.Xml.Linq,System.Diagnostics,System.Collections.Specialized,System.Configuration,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls /optioncompare:Binary /optionexplicit+ /optionstrict:custom /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /optioninfer+ /nostdlib /rootnamespace:Website /sdkpath:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7" /highentropyva+ /doc:obj\release\Website.xml /define:"CONFIG=\"release\",TRACE=-1,_MyType=\"Custom\",PLATFORM=\"AnyCPU\"" /reference:D:\Agent\_work\r5\a\Website\drop\bin\EntityFramework.dll,D:\Agent\_work\r5\a\Website\drop\bin\EntityFramework.SqlServer.dll,D:\Agent\_work\r5\a\Website\drop\bin\Intexx.Core.dll,D:\Agent\_work\r5\a\Website\drop\bin\itxcorlib.dll,"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.ComponentModel.DataAnnotations.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Configuration.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Core.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Data.DataSetExtensions.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Data.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Drawing.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.EnterpriseServices.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Web.ApplicationServices.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Web.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Web.DynamicData.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Web.Entity.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Web.Extensions.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Web.Services.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Xml.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7\System.Xml.Linq.dll" /debug+ /debug:pdbonly /optimize+ /out:obj\release\Website.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio17\Community\Team Tools\Static Analysis Tools\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /resource:obj\release\Website.Migrations._001.resources /resource:obj\release\Website.Resources.resources /target:library /utf8output App_Code\Enums.vb Bill.aspx.designer.vb Bill.aspx.vb Contact.aspx.designer.vb Contact.aspx.vb Default.aspx.designer.vb Default.aspx.vb Defects.aspx.designer.vb Defects.aspx.vb Donate.aspx.designer.vb Donate.aspx.vb Forum.aspx.designer.vb Forum.aspx.vb Jackson.aspx.designer.vb Jackson.aspx.vb Key.aspx.designer.vb Key.aspx.vb Laws.aspx.designer.vb Laws.aspx.vb Letters.aspx.designer.vb Letters.aspx.vb Losers.aspx.designer.vb Losers.aspx.vb Main.Master.designer.vb Main.Master.vb MenuItem.ascx.designer.vb MenuItem.ascx.vb Migrations1802040108464_001.Designer.vb Migrations1802040108464_001.vb Migrations\Configuration.vb Migrations\Defaults.vb Models\Db\Context.vb Models\Db\Loser.vb Models\Db\NewsItem.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\MyExtensions\MyWebExtension.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb" News.aspx.designer.vb News.aspx.vb Oops.aspx.designer.vb Oops.aspx.vb Pocket.aspx.designer.vb Pocket.aspx.vb Seventeenth.aspx.designer.vb Seventeenth.aspx.vb States.aspx.designer.vb States.aspx.vb Store.aspx.designer.vb Store.aspx.vb "D:\Agent\_work\_temp\.NETFramework,Version=v4.7.AssemblyAttributes.vb"
2018-02-27T04:48:44.2917430Z   Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild.0\Bin\Roslyn
2018-02-27T04:48:44.5307644Z   
2018-02-27T04:48:44.5357653Z _CopyFilesMarkedCopyLocal:
2018-02-27T04:48:44.5357653Z   Touching "D:\Agent\_work\r5\a\Website\drop\obj\release\Website.vbproj.CopyComplete".
2018-02-27T04:48:44.5567658Z CopyFilesToOutputDirectory:
2018-02-27T04:48:44.5577603Z   Copying file from "obj\release\Website.dll" to "bin\Website.dll".
2018-02-27T04:48:44.5587611Z   Website -> D:\Agent\_work\r5\a\Website\drop\bin\Website.dll
2018-02-27T04:48:44.5597611Z   Copying file from "obj\release\Website.pdb" to "bin\Website.pdb".
2018-02-27T04:48:44.5607636Z   Copying file from "obj\release\Website.xml" to "bin\Website.xml".
2018-02-27T04:48:44.5967639Z Done Building Project "D:\Agent\_work\r5\a\Website\drop\Website.vbproj" (default targets).
2018-02-27T04:48:44.6257666Z 
2018-02-27T04:48:44.6257666Z Build succeeded.
2018-02-27T04:48:44.6257666Z     0 Warning(s)
2018-02-27T04:48:44.6257666Z     0 Error(s)
2018-02-27T04:48:44.6257666Z 
2018-02-27T04:48:44.6257666Z Time Elapsed 00:00:02.29
2018-02-27T04:48:44.6868621Z ##[section]Finishing: Build solution $(System.DefaultWorkingDirectory)/Website/drop/Website.vbproj

QA.pubxml

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://www.website.local</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>https://server3:8172/msdeploy.axd</MSDeployServiceURL>
    <DeployIisAppPath>website</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>DOMAIN\User</UserName>
    <_SavePWD>True</_SavePWD>
    <PublishDatabaseSettings>
      <Objects xmlns="">
        <ObjectGroup Name="Website.Db.Context" Order="1" Enabled="False">
          <Destination Path="" />
          <Object Type="DbCodeFirst">
            <Source Path="DBMigration" DbContext="Website.Db.Context, Website" MigrationConfiguration="Website.Migrations.Configuration, Website" />
          </Object>
        </ObjectGroup>
        <ObjectGroup Name="Website.My.MySettings.DbConnectionString" Order="2" Enabled="False">
          <Destination Path="" />
          <Object Type="DbDacFx">
            <PreSource Path="Data Source=(local);Initial Catalog=Website;Integrated Security=False;Persist Security Info=False;User ID=username;Password=password" includeData="False" />
            <Source Path="$(IntermediateOutputPath)AutoScripts\Website.My.MySettings.DbConnectionString_IncrementalSchemaOnly.dacpac" dacpacAction="Deploy" />
          </Object>
          <UpdateFrom Type="Web.Config">
            <Source MatchValue="Data Source=(local);Initial Catalog=Website;Integrated Security=False;Persist Security Info=False;User ID=username;Password=password" MatchAttributes="$(UpdateFromConnectionStringAttributes)" />
          </UpdateFrom>
        </ObjectGroup>
      </Objects>
    </PublishDatabaseSettings>
  </PropertyGroup>
  <ItemGroup>
    <MSDeployParameterValue Include="$(DeployParameterPrefix)Website.Db.Context-Web.config Connection String" />
  </ItemGroup>
  <ItemGroup>
    <_ConnectionStringsToInsert Include="Website.Db.Context" />
  </ItemGroup>
</Project>

与 Azure 不同,设置从 VSTS/TFS 到这些定价托管服务器的持续部署没有 built-in 解决方案。

而且这是双向问题,TFS 也欢迎其他平台提供他们的官方扩展作为 Marketplace 中的 3 方任务。您可以在他们的网站上提交用户意见。

作为解决方法,TFS 还在生成代理中使用 MSBuild 来执行生成。 .publishsettings 也与 Azure 有关。如果您可以通过 Visual Studio 在本地使用 GoDaddy 的 Web 部署。它也应该能够在 TFS 中执行此操作。

看看这个教程,使用下面的 MSBuild 参数:

/p:DeployOnBuild=true /p:PublishProfile="sitename.com - Web Deploy.pubxml" /p:AllowUntrustedCertificate=true /p:UserName="uname" /p:Password="password" /p:VisualStudioVersion=14.0

更多详情请参考本教程:HOW TO SETUP VSTS CONTINUOUS DEPLOYMENT FOR GODADDY

但据此discussion看来,即使直接用Visual StudioWeb Deploy来处理GoDaddy也不太稳定。如果你遇到同样的问题,你可以处理他们的支持。

原来我没有在服务器上安装完整的 VS 工具集。我只安装了最低限度的,因为我只需要 VSTest 功能。

所以这次我更新并安装了 Web 和桌面,部署顺利进行。

感谢 Microsoft 支持服务为我提供的帮助。