1

I'm trying to build a project library that needs to be in the GAC, so I added the following line as a post build event:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" -if "$(TargetPath)"

For every even (second build, forth build, etc...) build execution I get this:

------ Build started: Project: Test.BusinessLogic, Configuration: Debug Any CPU ------   
Test.BusinessLogic -> C:\Users\Eran\Documents\Test\Trunk\Test.BusinessLogic\bin\Debug\Test.BusinessLogic.dll 
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1   
Copyright (c) Microsoft Corporation.  All rights reserved.

     Assembly successfully added to the cache

========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

Which is good - build was successful.

But for every odd (first build, third build, etc...) build execution I get this:

------ Build started: Project: Test.BusinessLogic, Configuration: Debug Any CPU ------   
Test.BusinessLogic -> C:\Users\Eran\Documents\Test\Trunk\Test.BusinessLogic\bin\Debug\Test.BusinessLogic.dll 
Microsoft (R) .NET Global Assembly Cache Utility.  Version 3.5.30729.1   
Copyright (c) Microsoft Corporation.  All rights reserved.

     Failure adding assembly to the cache:   Cannot create a file when that file already exists.    

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3717,9): error MSB3073: The command ""C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" -if "C:\Users\Eran\Documents\Test\Trunk\Test.BusinessLogic\bin\Debug\Test.BusinessLogic.dll"" exited with code 1.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

Which is bad and very weird.

How can I solve this issue?

Eran Betzalel
  • 4,105
  • 3
  • 38
  • 66
  • Well, odd error, environmental no doubt. Disable your virus scanner. Was using the 3.5 version of gacutil intentional? – Hans Passant Sep 27 '10 at 10:42
  • Yes, I'm not using .Net 4.0. I've disabled my AV, but the problem remains. I have a server and another desktop computer, both with VS 2010 that have the same problem. – Eran Betzalel Sep 27 '10 at 12:07
  • Do you have another project in the same solution referencing this project? If so, is it a project reference or an assembly reference? – Mattias S Sep 27 '10 at 14:52
  • @Mattias S, I have couple of projects that referencing it using GAC assembly reference. – Eran Betzalel Sep 28 '10 at 07:36
  • Is Copy Local set to true or false for those references? Does it make any difference if you change it? Does it make any differnce if you change it to a project reference? – Mattias S Sep 28 '10 at 12:12
  • @Mattias S, "Copy Local" has no effect on the situation. I know that "project reference" works, it's the "GAC reference" I'm having trouble with. – Eran Betzalel Sep 29 '10 at 08:53
  • So is there a reason why you have to reference the assembly directly instead of using a project reference? – Mattias S Sep 29 '10 at 09:30
  • @Mattias S, I decided to use GAC to create a single point of business logic across many asp.net application I have on the server. I you're suggesting using "project reference" for the test environment and "GAC reference" for the production, I can accept it as a workaround, but I think there is a real solution to this problem. – Eran Betzalel Sep 29 '10 at 09:58
  • Yes, reference the other project while working in Visual Studio. The CLR will handle picking up the correct assembly from the GAC at runtime. – Mattias S Sep 29 '10 at 11:33

2 Answers2

1

Do you hold a reference to this assembly?

Microsoft warns on using this tool when active referencing is present.

/uf <assembly_name>

Forces uninstall of an assembly by removing all traced references.
<assembly_name> is the full name of the assembly to remove.
Assembly will be removed unless referenced by Windows Installer.

!! Warning: use the /uf command with care as applications may fail to run !!

It better of to work with this tool outside of the visual studio, e.g. run it before compilation starts, and after your assembly gets built.

(in a separate script to VSD2010):

gacutil /uf <assemblyname>

build your assembly WITHOUT pre or post build actions that invoke gacutil

(in a separate script to VSD2010):

gacutil /if <assemblyname>
Olle Sjögren
  • 5,315
  • 3
  • 31
  • 51
Lior
  • 11
  • 1
0

I found a temporary work around that makes sure the registration worked - using this script for the post-build event:

:start 
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" -if "$(TargetPath)"
IF ERRORLEVEL 1 GOTO start
Eran Betzalel
  • 4,105
  • 3
  • 38
  • 66