1
votes

I'm trying out the Publish option for a Windows Service project in VS2012.

I use NLog, and have an NLog.config file. I also use SlowCheetah to transform that config file for each build configuration.

When I try to run the resulting setup.exe, I get the error

File, NLog.config, has a different computed hash than specified in manifest.

I suppose the hash was calculated on the pre-transformation version of NLog.config. How can I get the Publish wizard to use the correct, transformed version of NLog.config?

UPDATE (based on Sayed's request for more detail)

My Windows Service project uses NLog. The NLog.config file is marked with a Build Action of Content. It looks something like this (abbreviated version)

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

I'm using Slow Cheetah to add a transform for that file. The transform for the solution configuration QA looks like this:

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="[email protected]" from="[email protected]" 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>

The transformation causes the final NLog.config in the build output to be different than the NLog.config in the project (the transform rules as defined in NLog.QA.config are applied to the original NLog.config to get the final NLog.config).

When I use the Publish option to create a setup.exe and associated files, copy all of those files to a new QA machine, and attempt to run setup.exe, I get the error

File, NLog.config, has a different computed hash than specified in manifest.

Based on the error message I suspect that the computed hash specified in the manifest is based on the NLog.config file as it appears in the original project rather than on the transformed, final version produced by the build output.

Note that I do have a transform for my app.config as well. I did not receive a similar error for the transformed app.config. However, I don't know if that's because setup.exe gave up before getting to app.config, or if that is because the app.config case is handled correctly.

UPDATE 2

Here's the complete error message

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.

UPDATE 3

Looking at the files created by Publish, NLog.config.deploy is not the transformed file I would expect, but rather has the same contents as the original *NLog.config". The transform specified in NLog.QA.config was not applied.

The file size of NLog.config.deploy is 1353 bytes. However, the manifest () asserts that the file size should be 1696 bytes (which is exactly the correct transformed size)

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

The file is located under the folder where setup.exe is written, in

Application Files\MyService_1_0_0_0\NLog.config.deploy

Also, I notice in

C:...\MyProject\obj\QA\SlowCheetah

there is a file app.config but no file NLog.config.

UPDATE 4

Now when I do a normal build, with the solution set to QA, NLog.config is no longer being transformed. However, app.config is being transformed. Then, I went to the Publish tab of the project settings. I made no changes, but the .csproj was changed anyhow (there was a * next to the name... I didn't confirm what the changes were). Saved, built, and suddenly the NLog.config transform was applied. Published again, and suddenly the NLog.config was not applied again. Something with the publish settings is messing with SlowCheetah's ability to apply the transform to NLog.config.

Unfortunately at this point, I'll have to roll back to a previous version of the project that did not have any of the Publish stuff and get on with finishing the code. I hope this is enough information to track down the issue.

2
Can you provide more info here? I have no idea whats happening based on the current content.Sayed Ibrahim Hashimi
@SayedIbrahimHashimi: I added more detail. If you need more context to understand the problem, please let me know as specifically as you can what information would help you.Eric J.
Here is what I did. Create Win Svc project. Add QA sln/proj config. Add app.config and Add Transforms for Debug/Release/QA. Add nlog.config, add transforms for Debug/Release/QA. Right click publish on the win svc project. Copy the folder to a different machine and start setup.exe. It installed and ran fine, I received an error because it was a windows service. Here is my sample dl.dropbox.com/u/40134810/stackoverflow/12066623.zip. Can you share one that is failing?Sayed Ibrahim Hashimi
@SayedIbrahimHashimi: Hmmm. I can't reproduce the error with a brand new, simple project. Unfortunately I can't share the full project. I did add the entire error message. If there's anything specific I can check, I'm glad to do that. Should Publish not work with windows service projects?Eric J.

2 Answers

2
votes

A bit late to answer, but recently I had a similar problem when transformations were not applied to my config and xml and i received "File, SomeConfig.xml, has a different computed hash than specified in manifest." error.

The reason of this in my case was that both files had property Copy to Output Directory set to Copy Always, when I changed it to Do not copy (which is default value as I understand) everything began working as it should as well as ClickOnce installation.

0
votes

This solved it for me:

right-click on your config file (for me the issue was with app.config, not nlog.config) and select properties.

In the properties pane, set Copy to Output Directory = Copy Always (mine was defaulted to Do Not Copy).

Interestingly, this is the exact opposite from Max Viazovskyi's answer. But it was the only thing that worked for me after nearly a whole day of sifting through forums.

It's a Windows Forms project with config transforms and ClickOnce deployment.