MSBuild 社区任务 GacUtil 对我来说默默地失败了

发布于 2024-12-06 14:13:23 字数 1434 浏览 1 评论 0原文

我有一个 开源 .NET 项目,其主要工件是一个 DLL,需要安装到 GAC 才能使用它的主要用例。因此我想在 AfterBuild 任务期间安装它。我正在使用 MSBuild 社区扩展 中的 GacUtil msbuild 任务。它不起作用。

我的 MSBuild 代码,我从此处 是:

<Target Name="AfterBuild">
  <GacUtil Assemblies="$(TargetName)" />
</Target>

我使用的命令是 msbuild /t:AfterBuild /verbosity:diagnostic。我得到的错误是:

Done building target "_CheckForInvalidConfigurationAndPlatform" in project "JustAProgrammer.ADPR.csproj".
Target "AfterBuild" in project "e:\src\JustAProgrammer.ADPR\JustAProgrammer.ADPR\JustAProgrammer.ADPR.csproj" (entry point):
Using "GacUtil" task from assembly "C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll".
Task "GacUtil"
Done executing task "GacUtil" -- FAILED.
Done building target "AfterBuild" in project "JustAProgrammer.ADPR.csproj" -- FAILED.
Done Building Project "e:\src\JustAProgrammer.ADPR\JustAProgrammer.ADPR\JustAProgrammer.ADPR.csproj" (AfterBuild target(s)) -- FAILED.

我正在从以管理员身份运行的 cmd.exe 副本执行此命令,其路径中包含 gacutil.exe。我使用这个完全相同的命令提示符从 GAC 中成功安装和卸载该程序集,并仔细检查该程序集是否不在 c:\windows\Assembly 文件夹中。

如何找出 GacUtil 失败的原因?

I have an open source .NET project whose main artefact is a DLL that needs to be installed to the GAC for its primary use case. Therefore I want to install it during the AfterBuild task. I am using the GacUtil msbuild task from the MSBuild Community Extensions. It is not working.

My MSBuild code, which I got from here is:

<Target Name="AfterBuild">
  <GacUtil Assemblies="$(TargetName)" />
</Target>

The command I am using is msbuild /t:AfterBuild /verbosity:diagnostic. The error I get is:

Done building target "_CheckForInvalidConfigurationAndPlatform" in project "JustAProgrammer.ADPR.csproj".
Target "AfterBuild" in project "e:\src\JustAProgrammer.ADPR\JustAProgrammer.ADPR\JustAProgrammer.ADPR.csproj" (entry point):
Using "GacUtil" task from assembly "C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll".
Task "GacUtil"
Done executing task "GacUtil" -- FAILED.
Done building target "AfterBuild" in project "JustAProgrammer.ADPR.csproj" -- FAILED.
Done Building Project "e:\src\JustAProgrammer.ADPR\JustAProgrammer.ADPR\JustAProgrammer.ADPR.csproj" (AfterBuild target(s)) -- FAILED.

I am executing this command from a copy of cmd.exe running as administrator with gacutil.exe in its path. I used this very same command prompt to successfully install and uninstall this assembly from the GAC, and double checked that the assembly is not in the c:\windows\assembly folder.

How do I figure out why GacUtil is failing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心的位置 2024-12-13 14:13:23

看起来它试图用来访问该工具的路径是错误的(或者至少在我的情况下是错误的)。将“GacUtil”任务上的“ToolPath”属性设置为“$(FrameworkSDKDir)bin”,如下所示:

<Target Name="BeforeBuild">
    <GacUtil Command="Uninstall" ToolPath="$(FrameworkSDKDir)bin" Assemblies="$(TargetName)" ContinueOnError="true"/>
</Target>
<Target Name="AfterBuild">
  <GacUtil ToolPath="$(FrameworkSDKDir)bin" Assemblies="$(TargetPath)"/>
</Target>

It looks like the path it's trying to use to get to the tool is wrong (or at least it was in my case). Set the "ToolPath" property on the "GacUtil" task to "$(FrameworkSDKDir)bin" like so:

<Target Name="BeforeBuild">
    <GacUtil Command="Uninstall" ToolPath="$(FrameworkSDKDir)bin" Assemblies="$(TargetName)" ContinueOnError="true"/>
</Target>
<Target Name="AfterBuild">
  <GacUtil ToolPath="$(FrameworkSDKDir)bin" Assemblies="$(TargetPath)"/>
</Target>
脸赞 2024-12-13 14:13:23

您是否使用消息任务验证了 $(TargetName) 的值?

您可能必须在 build.proj 文件中指定一个属性:

  <PropertyGroup>
    <AssemblyPath></AssemblyPath>
  </PropertyGroup>

  <Target Name="AfterBuild">
    <GacUtil Assemblies="$(AssemblyPath)" />
  </Target>

然后从 Visual Studio 生成后事件传入属性值:

msbuild /t:AfterBuild /verbosity:diagnostic /p:AssemblyPath="$(TargetPath)"

Have you verified the value of $(TargetName) using the Message task?

You may have to specify a property in the build.proj file:

  <PropertyGroup>
    <AssemblyPath></AssemblyPath>
  </PropertyGroup>

  <Target Name="AfterBuild">
    <GacUtil Assemblies="$(AssemblyPath)" />
  </Target>

Then pass the property value in from the Visual Studio post-build event:

msbuild /t:AfterBuild /verbosity:diagnostic /p:AssemblyPath="$(TargetPath)"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文