GACed .net library project succesfully build only on second try
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 suc开发者_StackOverflow中文版cessful.
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?
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>
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
精彩评论