我一直在关注一个非常有用的blog post by Xinyang Qiu,用于将gacAssembly
元素添加到我的Web Deploy网站清单中。遗憾的是,the gacAssembly provider似乎无法打包本地程序集(即,不在GAC中),以便部署到GAC。在打包时,我收到以下错误:
清单中的一个或多个条目 'sitemanifest'无效。该 library'< full path> \< assembly>'可以 没有加载。给定的程序集名称 或代码库无效。 (例外 来自HRESULT:0x80131047)
我认为它正在解释我作为装配名称的一部分提供的路径,这当然不是我的意思。
有什么方法可以解决这个问题吗?是否可以将位于我本地目录中的程序集粘贴到Web Deploy程序包中以部署到服务器的GAC?
答案 0 :(得分:7)
Web Deploy 2.0有一个新的提供商,可以完全满足您的要求: gacInstall 提供商(请参阅http://technet.microsoft.com/en-us/library/gg607836(WS.10).aspx)允许嵌入源包中的程序集在GAC中进行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程序集还是本地程序集,都可以正常工作。
希望有所帮助:)