4

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?

Justin Dearing
  • 14,270
  • 22
  • 88
  • 161
  • Any chance msbuild or the task isn't finding the gacutil? I haven't looked at the dll to see whether the CE calls gacutil itself or if they wrote their own implementation. This was our approach to finding [gacutil](http://billfellows.blogspot.com/2010/03/post-build-event.html) but I'm sure the msbuild task will be better if you can get it working. Another thought would be to kick on process explorer and see what all files get accessed, maybe something weird is happening. – billinkc Oct 03 '11 at 17:10
  • . @billinkc Good general advice, but in this specific case, the Task does not have a reliance on the exe in v1.4 – Ruben Bartelink Nov 01 '12 at 10:05

2 Answers2

2

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>
Josh Gallagher
  • 5,211
  • 2
  • 33
  • 60
  • The error I now get is MSBUILD : warning MSB6006: "gacutil.exe" exited with code 1. E:\src\JustAProgrammer.ADPR\JustAProgrammer.ADPR\JustAProgrammer.ADPR.csproj(78,5): error MSB6006: "gacutil.exe" exited with code 1 – Justin Dearing Oct 07 '11 at 06:16
  • Well, this has got you past the original issue. Can you still successfully perform a separate gacutil command from the command line, passing it the $(TargetPath) value (i.e. "gacutil -i .\bin\Debug\JustAProgrammer.ADPR.dll" from the project root)? – Josh Gallagher Oct 10 '11 at 08:07
  • I have just noticed that you're using $(TargetName) rather than $(TargetPath) in your GacUtil. You need to use the latter in order to reference the assembly itself rather than just the path to the assembly. – Josh Gallagher Oct 10 '11 at 22:04
  • Justin, is your problem solved now? If it wasn't the TargetName/TargetPath part I identified, could you share the actual solution in an answer? – Josh Gallagher Oct 24 '11 at 09:31
  • Sorry, will revisit this week. – Justin Dearing Oct 24 '11 at 11:07
  • Ok I still get an error of 1 Here is the new xml : – Justin Dearing Nov 18 '11 at 03:07
  • @JustinDearing I realise now my previous comment wasn't clear. Look at the XML in my answer and you'll see that the uninstall uses TargetName and the install uses TargetPath. The XML you've put in your comment incorrection uses TargetPath for the uninstall. – Josh Gallagher Nov 18 '11 at 09:14
  • For clarity, v1.4 (and presumably later) do not have a reliance on gacutil.exe – Ruben Bartelink Nov 01 '12 at 10:04
0

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)"
Ashfaq Hussain
  • 331
  • 2
  • 11