1

我正在尝试构建一个需要在 GAC 中的项目库,因此我添加了以下行作为构建后事件:

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

对于每个偶数(第二次构建,第四次构建等)构建执行,我得到这个:

------ 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 ==========

这很好 - 构建成功。

但是对于每一个奇怪的(第一次构建,第三次构建等)构建执行我得到这个:

------ 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 ==========

这很糟糕而且很奇怪。

我该如何解决这个问题?

4

2 回答 2

1

你持有对这个程序集的引用吗?

存在活动引用时,Microsoft 会警告使用此工具。

/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.

!!警告:/uf小心使用该命令,因为应用程序可能无法运行!

最好在 Visual Studio 之外使用此工具,例如在编译开始之前和构建程序集之后运行它。

(在 VSD2010 的单独脚本中):

gacutil /uf <assemblyname>

在没有调用 gacutil 的构建前或构建后操作的情况下构建您的程序集

(在 VSD2010 的单独脚本中):

gacutil /if <assemblyname>
于 2011-03-08T07:36:14.487 回答
0

我找到了一个临时解决方法,以确保注册有效 - 将此脚本用于构建后事件:

:start 
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" -if "$(TargetPath)"
IF ERRORLEVEL 1 GOTO start
于 2010-10-04T09:06:03.763 回答