3

我一直在关注Xinyang Qiu 的一篇非常有用的博客文章,gacAssembly用于向我的 Web Deploy 站点清单添加元素。不幸的是,gacAssembly 提供者似乎无法打包本地程序集(即不在 GAC 中的程序集)以部署到 GAC。在打包时,我收到以下错误:

清单“sitemanifest”中的一个或多个条目无效。无法加载库“<完整路径>\<程序集>”。给定的程序集名称或代码库无效。(来自 HRESULT 的异常:0x80131047)

我认为它将我提供的路径解释为程序集名称的一部分,这当然不是我的意思。

有没有办法解决这个问题?是否可以将位于我本地目录中的程序集粘贴到 Web 部署包中以部署到服务器的 GAC?

4

1 回答 1

7

Web Deploy 2.0 有一个完全符合您要求的新提供程序:gacInstall提供程序(参见http://technet.microsoft.com/en-us/library/gg607836(WS.10).aspx)允许将程序集嵌入到源包在目的地被 GAC'd。

给定一个像这样的简单清单:

<sitemanifest>
  <gacInstall path="C:\Temp\MyAssembly.dll"  />
</sitemanifest>

..您可以创建一个包含这样的程序集的包:

msdeploy -verb:sync -source:manifest="path to manifest.xml" -dest:package="path to package.zip"

..然后使用该软件包将其安装在远程计算机上的 GAC 中:

msdeploy -verb:sync -source:package="path the package.zip" -dest:auto,computerName=REMOTEMACHINENAME

(当然,前提是程序集有一个强名称!)

现在,同样的原理可以应用于 VS Web 项目。但是,您需要确保在开发机器和目标 Web 服务器上都安装了 Web Deploy 2.x。而不是指定<MsDeploySourceManifest Include="gacAssembly">它必须是<MsDeploySourceManifest Include="gacInstall">.

这是我尝试过的完整的 {projectName}.wpp.targets 文件(基于问题中提到的博客文章中的文件):

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <CreatePackageOnPublish>True</CreatePackageOnPublish>
    <IncludeGacAssemblyForMyProject>True</IncludeGacAssemblyForMyProject>
    <UseMsdeployExe>False</UseMsdeployExe>
  </PropertyGroup>


  <PropertyGroup>
    <!--Targets get execute before this Target-->
    <OnBeforeCollectGacAssemblyForPackage Condition="'$(OnBeforeCollectGacAssemblyForPackage)'==''">
    </OnBeforeCollectGacAssemblyForPackage>
    <!--Targets get execute after this Target-->
    <OnAfterCollectGacAssemblyForPackage Condition="'$(OnAfterCollectGacAssemblyForPackage)'==''">
    </OnAfterCollectGacAssemblyForPackage>

    <CollectGacAssemblyForPackageDependsOn Condition="'$(CollectGacAssemblyForPackageDependsOn)'==''">
      $(OnBeforeCollectGacAssemblyForPackage);
      Build;
    </CollectGacAssemblyForPackageDependsOn>

    <AfterWriteItemsToSourceManifest>
      $(AfterWriteItemsToSourceManifest);
      _PrintSourceManifests;
    </AfterWriteItemsToSourceManifest>
  </PropertyGroup>


  <PropertyGroup>
    <IncludeGacAssemblyForMyProject Condition="'$(IncludeGacAssemblyForMyProject)'==''">False</IncludeGacAssemblyForMyProject>
    <AfterAddContentPathToSourceManifest Condition="'$(AfterAddContentPathToSourceManifest)'==''">
      $(AfterAddContentPathToSourceManifest);
      CollectGacAssemblyForPackage;
    </AfterAddContentPathToSourceManifest>
  </PropertyGroup>


  <Target Name="CollectGacAssemblyForPackage"
          DependsOnTargets="$(CollectGacAssemblyForPackageDependsOn)"
          Condition="$(IncludeGacAssemblyForMyProject)">

    <ItemGroup>
      <MyGacAssembly Include="@(ReferencePath)" Condition="'%(ReferencePath.GacInstall)'=='true'" />
    </ItemGroup>

    <Message Text="MsDeployPath: $(MSDeployPath)" /> <!-- For debugging -->
    <Message Text="Adding [gacInstall]: %(MyGacAssembly.Identity)" />

    <ItemGroup>
      <MsDeploySourceManifest Include="gacInstall" Condition="$(IncludeGacAssemblyForMyProject)">
        <Path>%(MyGacAssembly.Identity)</Path>
      </MsDeploySourceManifest>
    </ItemGroup>

    <CallTarget Targets="$(OnAfterCollectGacAssemblyForPackage)" RunEachTargetSeparately="false" />
  </Target>

  <Target Name="_PrintSourceManifests">
    <!-- Just for debugging -->
    <Message Text="Exporting Manifests:" />
    <Message Text=" @(MsDeploySourceManifest) : %(MsDeploySourceManifest.Path)" />
  </Target>

</Project>

我添加的另一件事是如何选择gacInstall程序集,即通过添加到project.csproj文件<GacInstall>True</GacInstall>中的相应<Reference/>标签的元数据条目:

<Reference Include="System.Data">
  <GacInstall>True</GacInstall>
</Reference>
<Reference Include="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f430b784831ac64e, processorArchitecture=MSIL">
  <HintPath>..\..\LIB\MyAssembly.dll</HintPath>
  <GacInstall>True</GacInstall>
</Reference>

无论您引用的是 GAC 程序集还是本地程序集,这都有效。

希望有帮助:)

于 2011-05-03T22:33:16.433 回答