微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

.net – Web Deploy可以为目标服务器的GAC打包本地程序集吗?

我一直在关注一个非常有用的 blog post by Xinyang Qiu,用于将gacAssembly元素添加到我的Web Deploy站点清单中.遗憾的是,the gacAssembly provider似乎无法将本地程序集(即不在GAC中的程序集)打包以部署到GAC.在打包时,我收到以下错误

One or more entries in the manifest
‘sitemanifest’ are not valid. The
library ‘<full path>\<assembly>’ Could
not be loaded. The given assembly name
or codebase was invalid. (Exception
from HRESULT: 0x80131047)

我认为它正在解释我作为装配名称的一部分提供的路径,这当然不是我的意思.

这有什么办法吗?是否可以将位于我本地目录中的程序集粘贴到Web Deploy程序包中以部署到服务器的GAC?

解决方法

Web Deploy 2.0有一个新的提供程序,可以满足您的要求:gacInstall提供程序(参见 http://technet.microsoft.com/en-us/library/gg607836(WS.10).aspx)允许嵌入在源程序包中的程序集在目标位置进行GAC.

给出一个简单的清单:

<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 Deploy 2.x既安装在开发机器上,也安装在目标Web服务器上.而不是指定< 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程序集,即通过元数据条目< GacInstall> True< / GacInstall>添加到相应的< Reference /> project.csproj文件中的标签

<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程序集还是本地程序集,它都可以工作.

希望有帮助:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐