【问题标题】:MSBuild on TFS failed - WebDeploy PackageTFS 上的 MSBuild 失败 - WebDeploy 包
【发布时间】:2013-03-22 10:49:49
【问题描述】:

我目前正在为一个项目进行构建,但我在 TFS 构建方面遇到了困难。
我只想创建一个 zip 包,使用 TFS 构建,带有来自 IIS Express 的参数。

CSPROJ 配置:

IIS Express 存在于我的机器和构建服务器上(我可以访问项目中的 *.svc 文件)。
一切都在源代码控制上。

当我在我的机器上使用“构建部署包”时,我得到了 zip。
当我在构建服务器上使用“构建部署包”时,我得到了 zip。
当我在两者上使用 MSBuild 的命令行时,我得到了 zip。

有问题的命令行:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" "C:\WORKSPACES\[...]\Project.csproj" /p:Platform=AnyCPU;Configuration=Release /p:DeployTarget=Package /p:DeployOnBuild=true;DefaultPackageFileName=ZipName.zip

但是当我将相同的命令行放入构建中时,它会失败:

"C:\Builds\2\[...]\Project.csproj" (default target) (1) ->
(PackageUsingManifest target) -> 
  C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3009,5): error : Web deployment task failed.(Object of type 'manifest' and path 'C:\Builds\2\Project Release\Binaries\_PublishedWebsites\Project_Package\Project.SourceManifest.xml' cannot be created.) [C:\Builds\2\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3009,5): error :  [C:\Builds\2\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3009,5): error : Object of type 'manifest' and path 'C:\Builds\2\Project Release\Binaries\_PublishedWebsites\Project_Package\Project.SourceManifest.xml' cannot be created. [C:\Builds\2\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3009,5): error : One or more entries in the manifest 'sitemanifest' are not valid. [C:\Builds\2\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(3009,5): error : Site '' does not exist. [C:\Builds\2\[...]\Project.csproj]

附加信息,第 3009 行参考:

<VSMSDeploy Condition="!$(UseMsdeployExe)"
   MSDeployVersionsToTry="$(_MSDeployVersionsToTry)"
   Source="@(MsDeploySourceProviderSetting)"
   Destination="@(MsDeployDestinationProviderSetting)"
   DeploymentTraceLevel="$(PackageTraceLevel)"
   DisableLink="$(PackageDisableLinks)"
   EnableLink="$(PackageEnableLinks)"
   DeclareParameterItems="@(_Package_MsDeployDeclareParameters)"
   OptimisticParameterDefaultValue="$(EnableOptimisticParameterDefaultValue)"
   ImportDeclareParametersItems="$(_VsPackageParametersFile)"
   ReplaceRuleItems="@(MsDeployReplaceRules)"
   RetryAttempts="$(RetryAttemptsForDeployment)">

我知道我遗漏了一些东西,但我看不出是什么...所以,如果您有建议...非常欢迎! :)

当我登录构建服务器时,tfs 构建没有使用与我相同的帐户运行。
IIS Express 是否可以通过 tfs 构建很好地启动?
当我查看C:\Users\svcTfsBuild\Documents 时,没有 IISExpress 目录,就像我的用户一样(svcTfsBuild 是 TFS Build 的服务帐户)。

主要目标:

  • 获取带有这些参数的 tfs 构建的 zip 包(zip 包中的parameters.xml)。
  • 有一个压缩包,我们可以在导入时指定应用程序池和物理路径。

像这样:

<parameters>
  <parameter name="IIS Web Application Name" defaultValue="Default Web Site/Project" tags="IisApp">
    <parameterEntry kind="ProviderPath" scope="AppHostConfig" match="^ProjectTest/Project$" />
    <parameterEntry kind="ProviderPath" scope="contentPath" match="^C:\\WORKSPACES\\[...]\\obj\\Release\\Package\\PackageTmp$" />
    <parameterEntry kind="ProviderPath" scope="setAcl" match="^C:\\WORKSPACES\\[...]\\obj\\Release\\Package\\PackageTmp$" />
  </parameter>
  <parameter name="IIS Web Application Pool Name" defaultValue="ASP.NET v4.0">
    <parameterEntry kind="DeploymentObjectAttribute" scope="application" match="application[@applicationPool='Clr4IntegratedAppPool']/@applicationPool" />
  </parameter>
  <parameter name="IisVirtualDirectoryPhysicalPath" defaultValue="D:\CompanyName\Project" tags="PhysicalPath">
    <parameterEntry kind="DestinationVirtualDirectory" scope=".*" match="^C:\\WORKSPACES\\[...]$" />
  </parameter>
</parameters>

注意:我们可以直接在 csproj 上的 parameters.xml 中指定配置,因为工作空间在我们的机器上不一样,在 tfs 构建服务器上...

我希望这很清楚

编辑:drk 的建议

就像你说的,我从服务帐户运行命令行,得到了这个,特别是:

GenerateMsdeployManifestFiles:
  Generate source manifest file for Web Deploy package/publish ...
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018: The "IsCleanMSDeployPackageNeeded" task failed unexpectedly. [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Web.Deployment.DeploymentException: Object of type 'package' and path 'C:\WORKSPACES\[...]\obj\Release\Package\Project.zip' cannot be created. ---> Microsoft.Web.Deployment.DeploymentException: The Zip package 'C:\WORKSPACES\[...]\obj\Release\Package\Project.zip' could not be loaded. ---> System.UnauthorizedAccessException: Access to the path 'C:\WORKSPACES\[...]\obj\Release\Package\Project.zip' is denied. [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.Win32Native.RaiseIOExceptionFromErrorCode(Win32ErrorCode errorCode, String maybeFullPath) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.FileStreamEx.CreateInstance(String path, FileMode fileMode, FileAccess fileAccess, FileShare fileShare) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.ZipFile.Load() [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.ZipPackageProvider..ctor(DeploymentProviderContext providerContext, DeploymentBaseContext baseContext, String path) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    --- End of inner exception stack trace --- [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.ZipPackageProvider.GetAttributes(DeploymentAddAttributeContext addContext) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.DeploymentObject.EnsureValidAttributes() [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    --- End of inner exception stack trace --- [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.DeploymentManager.CreateObjectPrivate(DeploymentProviderContext providerContext, DeploymentBaseOptions baseOptions, DeploymentObject sourceObject) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.DeploymentManager.CreateObject(DeploymentProviderOptions providerOptions, DeploymentBaseOptions baseOptions) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.DeploymentManager.CreateObject(String provider, String path, DeploymentBaseOptions baseOptions) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Deployment.DeploymentManager.CreateObject(DeploymentWellKnownProvider provider, String path) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    --- End of inner exception stack trace --- [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Publishing.Tasks.DynamicAssembly.CallStaticMethod(String typeName, String methodName, Object[] arguments) [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Web.Publishing.Tasks.IsCleanMSDeployPackageNeeded.Execute() [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\WORKSPACES\[...]\Project.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(2850,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) [C:\WORKSPACES\[...]\Project.csproj]
Done Building Project "C:\WORKSPACES\[...]\Project.csproj" (default targets) -- FAILED.

Build FAILED.

我检查了服务帐户(在我的例子中是 SvcTfsBuild)。 他可以完全控制工作区(所以是源代码)。 而且我的账号和 SvcTfsBuild 账号在同一个组(本地管理员)。

但是 TFS BUILD 日志(详细模式)没有显示任何权限问题...

编辑 2013/03/25

我已取消选中“Web”选项卡中的“使用 IIS Express”复选框。
该构建生成了良好的 zip 包。
所以,我认为只有 IIS Express 存在问题。

在构建中,我在“在代理上运行”序列上有一个“InvokeProcess”,就在“CreateLabel”之后。
它使用这些参数启动 ISS Express:

/site:Project-Site

在日志文件中,我的 Result 为 0(因此,我假设 ISS Express 启动良好,如果没有,它应该抛出异常)。 但是,如果命令行格式不正确或错误(即:不能将 /site 和 /path 组合在一起),结果也是 0。
如果我以这种方式启动 ISS Express,构建将停止(iisexpress 等待手动操作停止或只是收听)。

编辑 2 2013/03/25

为了在构建的同时启动 IIS Express,我做了这个:

在并行上,我有一个名为“BuildFinished”的变量,在构建过程的最后(左侧)中设置为 True。

但是,我又遇到了同样的错误(站点“不存在”)。

当通过“构建部署包”(在 VS2010 中)和通过 TFBUILD 构建时,我还发现了两个 Project.SourceManifest.xml 之间的区别。

构建部署包:

<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
  <appHostConfig path="Project-Site/Project" />
  <contentPath path="C:\WORKSPACES\Project\obj\Release\Package\PackageTmp" />
  <setAcl path="C:\WORKSPACES\Project\obj\Release\Package\PackageTmp" setAclResourceType="Directory" />
  <setAcl path="C:\WORKSPACES\Project\obj\Release\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>

TFBUILD:

<?xml version="1.0" encoding="utf-8"?>
<sitemanifest>
  <appHostConfig path="/Project" />
  <contentPath path="C:\Builds\1\Project\obj\Release\Package\PackageTmp" />
  <setAcl path="C:\Builds\1\Project\obj\Release\Package\PackageTmp" setAclResourceType="Directory" />
  <setAcl path="C:\Builds\1\Project\obj\Release\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" />
</sitemanifest>

路径值不一样。

【问题讨论】:

  • 我建议在构建服务帐户下运行命令以查看完整输出,听起来像是权限问题。 tfs 构建在哪个帐户下运行?
  • 服务帐户的权限问题是正确的。我已经用相关输出编辑了问题。
  • 尝试在 svc 帐户下手动创建该文件,检查权限或所有权(如果存在)和文件夹,也可能与 UAC 相关。
  • 好吧,我已经按照你的建议做了。这个更好。现在,我遇到了与构建中相同的错误^^(站点''不存在。)
  • 我手动启动了 IIS Express,然后从命令行构建。有用。但是,即使为服务帐户启动 IIS Express,构建也会失败并显示相同的消息。所以,我今天就结束了,下周一的下一集。

标签: visual-studio-2010 tfsbuild iis-express webdeploy


【解决方案1】:

经过几次尝试,我认为问题在于 IIS Express 和 MSDeploy 之间无法一起工作(这是“Site '' does not exist.”的说法)。

因此,我们并没有试图让它工作,而是改变主意使用一种有效的配置:在构建过程中修改 csproj 以使用 IIS。

第 1 步:构建服务器上的 IIS

  1. 创建应用程序池:名称和框架版本是重要的两件事。仅此而已。
  2. 创建应用程序:名称和应用程序池很重要。您可以使用 C:\temp 作为物理路径。

第 2 步:构建的定义
您有两个选择:创建自定义构建活动(更好的一个)或在 xaml 中执行(丑陋的一个)。
目标,是有以下步骤:

  1. 在“Run On Agent”序列中,就在“If Create Label”之后
  2. 删除目标 csproj 上的只读属性(TFS 创建的工作空间上的那个)
  3. 阅读 csproj 的内容
  4. 替换以下 XML 标记

&lt;UseIISExpress&gt;True&lt;/UseIISExpress&gt; &lt;UseIISExpress&gt;False&lt;/UseIISExpress&gt;
&lt;UseIIS&gt;False&lt;/UseIIS&gt; &lt;UseIIS&gt;True&lt;/UseIIS&gt;
&lt;IncludeIisSettings&gt;False&lt;/IncludeIisSettings&gt; &lt;IncludeIisSettings&gt;true&lt;/IncludeIisSettings&gt;
&lt;IISUrl&gt;{IIS Express URL}&lt;/IISUrl&gt; &lt;IISUrl&gt;{IIS URL}&lt;/IISUrl&gt;
/!\ 注意:布尔值可以是 True 或 true!
/!\ Beware2:如果使用 Cassini,IISUrl 的标签可能有自动换行,例如:

`<IISUrl>  
</IISUrl>`  

这仅发生在 4 位开发人员的其中一台机器上。

{IIS Express URL}:类似于 IIS Express 的 http://localhost:8080/http://localhost:8080/Application 或 Cassini 的空。
{IIS URL}:类似于http://localhost/Application

 
最后,用修改内容覆盖 csproj(记住,TFS 工作区中的那个,而不是源代码控制上的那个)。

{IIS Express URL} 和 {IIS URL} 可以是构建中的参数,但前提是构建一个接一个地采用 csproj(1 个构建 = 1 个 zip 包,因此必须修改 1 个 csproj)。

 

使用该解决方案(我认为有一个更好的解决方案,我不知道),我们使用我们知道它有效的配置。

在 IIS 中导入压缩包时,可以更改应用程序池和物理路径。
这就是我们的目标。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 1970-01-01
    相关资源
    最近更新 更多