Tuesday, June 16, 2009

The "ResourceKeySource" task failed unexpectedly on build server

I have been working to get one of our projects to build on our CruiseControl.net
server. This is a Winfoms app that uses several third party controls. I had been
unable to complete a build and was getting the following error during the build:


c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets (1805,7):

errorMSB4018: The "ResolveKeySource" task failed unexpectedly.

System.InvalidOperationException: Showing a modal dialog box or form when the application
is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification
or DefaultDesktopOnly style to display a notification from a service application.

at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)

at System.Windows.Forms.Form.ShowDialog()

at Microsoft.Build.Tasks.ResolveKeySource.ResolveManifestKey()

at Microsoft.Build.Tasks.ResolveKeySource.Execute()

at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy,
ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean&
taskResult)

I did some research on the message and found that MSBuild was trying to install
a key file for the current user and throwing up a dialog to prompt for a password.

I logged into the console of the build server and ran the install from MSBuild as
myself and got it to run. When prompted for the key file, I entered my password. Everything worked. But, when I tried to kick off a build from CruiseControl.net again, no dice. I knew there was an issue with that key file dialog. When I ran the build from the command line again, it did not prompt me for a password. So, all I needed to do was to get that key installed once and I thought I would be good.

Using the information in the article on run the command-line as the LocalSystem, I ran the following command from the command line

at [current time + 1 min] /interactive cmd.exe

This opened a new command window a minute later that was running as the LocalSystem account. Using this command window, I was able to run msbuild. I was prompted for the key password, which I entered. The build succeeded nicely. Once this was working, I kicked off a build of the project from CruiseControl.net and Bingo!, it worked.