我正在尝试 VS2012 中 Windows 服务项目的发布选项。
我使用 NLog,并且有一个 NLog.config 文件。我还使用 SlowCheetah 为每个构建配置转换该配置文件。
当我尝试运行生成的 setup.exe 时,出现错误
文件 NLog.config 的计算哈希值与清单中指定的哈希值不同。
我想哈希是在 NLog.config 的预转换版本上计算的。如何让发布向导使用正确的、转换后的 NLog.config 版本?
更新(基于 Sayed 要求提供更多详细信息)
我的 Windows 服务项目使用 NLog。NLog.config 文件标有内容的构建操作。它看起来像这样(缩写版)
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="ferr" fileName="C:/MyPath/Error.log"
archiveFileName="C:/MyPath/Error.{#}.txt"
archiveEvery="Day"
archiveNumbering="Rolling"
maxArchiveFiles="28"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="ferr" />
</rules>
</nlog>
我正在使用Slow Cheetah为该文件添加转换。解决方案配置 QA 的转换如下所示:
NLog.QA.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
<targets>
<target xsi:type="Mail" name="m"
to="me@not.really" from="notify@not.really" html="True"
subject="QA ERROR on ${machinename}"
smtpServer="127.0.0.1"
layout="${longdate} ${uppercase:${level}} ${message}" xdt:Transform="Insert" />
</targets>
<rules>
<logger name="*" minlevel="Fatal" writeTo="m" xdt:Transform="Insert" />
</rules>
</nlog>
转换导致构建输出中最终的 NLog.config 与项目中的 NLog.config 不同(将 NLog.QA.config 中定义的转换规则应用于原始 NLog.config 以获得最终的 NLog.config )。
当我使用“发布”选项创建 setup.exe 和相关文件,将所有这些文件复制到新的 QA 机器并尝试运行 setup.exe 时,我收到错误消息
文件 NLog.config 的计算哈希值与清单中指定的哈希值不同。
根据错误消息,我怀疑清单中指定的计算哈希是基于原始项目中出现的 NLog.config 文件,而不是构建输出生成的转换后的最终版本。
请注意,我的 app.config 也有一个转换。我没有收到转换后的 app.config 的类似错误。但是,我不知道这是因为 setup.exe 在进入 app.config 之前放弃了,还是因为 app.config 案例处理正确。
更新 2
这是完整的错误信息
PLATFORM VERSION INFO
Windows : 6.0.6002.131072 (Win32NT)
Common Language Runtime : 4.0.30319.17929
System.Deployment.dll : 4.0.30319.17929 built by: FX45RTMREL
clr.dll : 4.0.30319.17929 built by: FX45RTMREL
dfdll.dll : 4.0.30319.17929 built by: FX45RTMREL
dfshim.dll : 4.0.41209.0 (Main.041209-0000)
SOURCES
Deployment url : file:///C:/Xfer/MyService/MyService.application
Application url : file:///C:/Xfer/MyService/Application%20Files/MyService_1_0_0_3/MyService.exe.manifest
IDENTITIES
Deployment Identity : MyService.application, Version=1.0.0.3, Culture=neutral, PublicKeyToken=56e62aa7113b4840, processorArchitecture=msil
Application Identity : MyService.exe, Version=1.0.0.3, Culture=neutral, PublicKeyToken=56e62aa7113b4840, processorArchitecture=msil, type=win32
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of C:\Xfer\MyService\MyService.application resulted in exception. Following failure messages were detected:
+ File, NLog.config, has a different computed hash than specified in manifest.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [8/22/2012 11:10:55 PM] : Activation of C:\Xfer\MyService\MyService.application has started.
* [8/22/2012 11:10:55 PM] : Processing of deployment manifest has successfully completed.
* [8/22/2012 11:10:55 PM] : Installation of the application has started.
* [8/22/2012 11:10:55 PM] : Processing of application manifest has successfully completed.
* [8/22/2012 11:10:57 PM] : Found compatible runtime version 4.0.30319.
* [8/22/2012 11:10:57 PM] : Request of trust and detection of platform is complete.
ERROR DETAILS
Following errors were detected during this operation.
* [8/22/2012 11:10:58 PM] System.Deployment.Application.InvalidDeploymentException (HashValidation)
- File, NLog.config, has a different computed hash than specified in manifest.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.ComponentVerifier.VerifyFileHash(String filePath, Hash hash)
at System.Deployment.Application.ComponentVerifier.VerifyFileHash(String filePath, HashCollection hashCollection)
at System.Deployment.Application.ComponentVerifier.FileComponent.Verify()
at System.Deployment.Application.ComponentVerifier.VerifyComponents()
at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
更新 3
查看 Publish 创建的文件,NLog.config.deploy不是我期望的转换文件,而是与原始*NLog.config" 具有相同的内容。未应用NLog.QA.config中指定的转换。
NLog.config.deploy的文件大小为 1353 字节。但是,manifest() 断言文件大小应该是 1696 字节(这正是正确的转换大小)
<file name="NLog.config" size="1696">
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>IbzW1PndPFYBt59Yrcl6Ax8F5GFX3VVco7wIdDrV6Fo=</dsig:DigestValue>
</hash>
</file>
该文件位于写入 setup.exe 的文件夹下,在
应用程序文件\MyService_1_0_0_0\NLog.config.deploy
另外,我注意到
C:...\MyProject\obj\QA\SlowCheetah
有一个文件app.config但没有文件NLog.config。
更新 4
现在,当我进行正常构建时,将解决方案设置为 QA,NLog.config 不再被转换。但是,app.config正在被转换。然后,我转到项目设置的发布选项卡。我没有做任何更改,但是 .csproj 无论如何都被更改了(名称旁边有一个 * ......我没有确认更改是什么)。保存、构建,然后突然应用了 NLog.config 转换。再次发布,突然没有再次应用 NLog.config。发布设置的某些东西干扰了 SlowCheetah 将转换应用于 NLog.config 的能力。
不幸的是,在这一点上,我将不得不回滚到没有任何发布内容的项目的先前版本并继续完成代码。我希望这是足够的信息来追踪问题。