Error when using with MSbuild/TeamCity

Topics: Bugs
Jan 6, 2009 at 11:16 AM
Hello,

I'm trying to generate our project's documentation with DocProject using TeamCity as our build server.
The DocProject project is simply part of the main Visual Studio 2008 solution, and is built using the sln2008 build runner in TeamCity 4.0, on a Windows Server 2003 machine.

Unfortunately the build fails most of the time with the following error in the build logs (reported by TeamCity) :

[12:01:27]: sln2008 output:
Finished processing 0 EDMX files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
_CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
TestWatchListPlugin -> D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Features\WatchListPlugin\TestWatchListPlugin\bin\Debug\TestWatchListPlugin.dll
Done Building Project "D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Features\WatchListPlugin\TestWatchListPlugin\TestWatchListPlugin.csproj" (default targets).
Project "D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\NVision.sln" (2) is building "D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Features\OrderBookPlugin\TestOrderBookPlugin\TestOrderBookPlugin.csproj" (78) on node 0 (default targets).
Processing 0 EDMX files.
Finished processing 0 EDMX files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
_CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
TestOrderBookPlugin -> D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Features\OrderBookPlugin\TestOrderBookPlugin\bin\Debug\TestOrderBookPlugin.dll
Done Building Project "D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Features\OrderBookPlugin\TestOrderBookPlugin\TestOrderBookPlugin.csproj" (default targets).
Done Building Project "D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\NVision.sln" (Build target(s)).

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: A call is made on an inactive IBuildEngine interface corresponding to a task that already finished execution.
at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args)
at Microsoft.Build.BuildEngine.EngineProxy.LogMessageEvent(BuildMessageEventArgs e)
at Microsoft.Build.Utilities.TaskLoggingHelper.LogMessage(MessageImportance importance, String message, Object[] messageArgs)
at Microsoft.Build.Utilities.TaskLoggingHelper.LogMessage(String message, Object[] messageArgs)
at DaveSexton.DocProject.MSBuild.MSBuildTrace.TraceLine(String message)
at DaveSexton.DocProject.BuildContext.<>c__DisplayClass13.<TraceLine>b__12()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
[12:01:27]: Process exit code: -532459699

The even viewer shows the folllowing entries:
Event Type:    Error
Event Source:    .NET Runtime 2.0 Error Reporting
Event Category:    None
Event ID:    5000
Date:        06/01/2009
Time:        11:59:51
User:        N/A
Computer:    VSS2-TEAMCITY
Description:
EventType clr20r3, P1 msbuild.exe, P2 3.5.30729.1, P3 488efbd7, P4 mscorlib, P5 2.0.0.0, P6 4889dc80, P7 f4f, P8 7, P9 n3ctrye2kn3c34sgl4zqyrbfte4m13nb, P10 NIL.
And
Event Type:    Error
Event Source:    DocProject
Event Category:    None
Event ID:    0
Date:        06/01/2009
Time:        11:55:19
User:        N/A
Computer:    VSS2-TEAMCITY
Description:
An error occurred while initializing the DocProject Add-In.

System.Runtime.InteropServices.COMException (0x800A0001): Exception from HRESULT: 0x800A0001
   at EnvDTE80.Windows2.CreateToolWindow2(AddIn Addin, String Assembly, String Class, String Caption, String GuidPosition, Object& ControlObject)
   at DaveSexton.DocProject.DocProjectEnvironment.RegisterToolWindow(ToolWindow item)
   at DaveSexton.DocProject.ToolWindowCollection.InsertItem(Int32 index, ToolWindow item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at DaveSexton.DocProject.DocProjectEnvironment.InitializeVSExtensions()
   at DaveSexton.DocProject.DocProjectEnvironment.Initialize()
   at DaveSexton.DocProject.DocProjectEnvironment.Initialize(IEnvironmentHost hostUI)
   at DaveSexton.DocProject.DocProjectAddIn.Extensibility.IDTExtensibility2.OnStartupComplete(Array& custom)
The last entry is similar to what was happening in a another bug related to the Visual Studio addin (solved in item #15166). But in this case I'm not using Visual Studio but MSBuild, so I don't  really understand what this event is about...

Note that the build actually succeeded on some occasions, though under no apparent change in the build server configuration.

Any idea?

Thanks,

Nicolas


Coordinator
Jan 6, 2009 at 2:44 PM
Hi Nicolas, 

I'm using TeamCity 3.1.2 (build 6881) at work to build DocProjects and I've never seen this issue.  Although, all of our projects use the MSBuild runner so maybe try that instead (you should be able to build an .sln with the MSBuild runner as well).

I'll look into upgrading to TeamCity 4.0 (which I wanted to do anyway) and see if I can come up with a solution, although it may take a week or two before I can get around to it.

- Dave
Jan 6, 2009 at 3:38 PM
Thanks for the quick reply.
I tried to use the MSBuild runner to build the solution, and got the exact same error message as with the solution runner.

I then tried to only build the DocProject C# project, and now I get this message:

[16:23:58]: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets warning MSB3088: Could not read state file "obj\Debug\ResolveAssemblyReference.cache". Unable to cast object of type 'Microsoft.Build.Tasks.SystemState' to type 'Microsoft.Build.Tasks.StateFileBase'.
[16:24:02]: C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40, 5): error MSB4018: The "BuildDocProject" task failed unexpectedly.
System.ArgumentException: The specified project file was not created from a DocProject or DocSite template.

You must first use Visual Studio to create a new project that is based on a DocProject or DocSite template and then you can open it with this program.
Parameter name: task
at DaveSexton.DocProject.MSBuild.MSBuildDocProject..ctor(Engine engine, BuildDocProject task, String solutionPath)
at DaveSexton.DocProject.MSBuild.BuildDocProject.get_Project()
at DaveSexton.DocProject.MSBuild.BuildDocProject.get_Engine()
at DaveSexton.DocProject.MSBuild.BuildDocProject.Execute()
at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)
[16:24:02]: MSBuild output:
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at DaveSexton.DocProject.MSBuild.BuildDocProject.get_Project()
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at DaveSexton.DocProject.MSBuild.BuildDocProject.get_Engine()
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at DaveSexton.DocProject.MSBuild.BuildDocProject.Execute()
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)
Done Building Project "D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Documentation\NVision.Documentation\NVision.Documentation.csproj.teamcity.patch.tcprojx" (default targets) -- FAILED.

Build FAILED.

"D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Documentation\NVision.Documentation\NVision.Documentation.csproj.teamcity.patch.tcprojx" (default target) (1) ->
(ResolveAssemblyReferences target) ->
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning MSB3088: Could not read state file "obj\Debug\ResolveAssemblyReference.cache". Unable to cast object of type 'Microsoft.Build.Tasks.SystemState' to type 'Microsoft.Build.Tasks.StateFileBase'.


"D:\TeamCity\buildAgent\work\79185615bac01f59\NVision\Documentation\NVision.Documentation\NVision.Documentation.csproj.teamcity.patch.tcprojx" (default target) (1) ->
(CoreBuildHelp target) ->
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: The "BuildDocProject" task failed unexpectedly.
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: System.ArgumentException: The specified project file was not created from a DocProject or DocSite template.
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018:
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: You must first use Visual Studio to create a new project that is based on a DocProject or DocSite template and then you can open it with this program.
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: Parameter name: task
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at DaveSexton.DocProject.MSBuild.MSBuildDocProject..ctor(Engine engine, BuildDocProject task, String solutionPath)
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at DaveSexton.DocProject.MSBuild.BuildDocProject.get_Project()
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at DaveSexton.DocProject.MSBuild.BuildDocProject.get_Engine()
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at DaveSexton.DocProject.MSBuild.BuildDocProject.Execute()
C:\Program Files\Dave Sexton\DocProject\bin\DaveSexton.DocProject.targets(40,5): error MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)

1 Warning(s)
1 Error(s)

Time Elapsed 00:00:06.28
[16:24:02]: Process exit code: 1
Note that the project was created in Visual Studio, and it builds fine locally (and on the build server if I use manually msbuild), so I think the project is ok.

Also, my build agent service is configured to run as the local system account. Could this affect the build? Do you have the same configuration for you build agent?

- Nicolas
Mar 19, 2009 at 9:53 PM

I've seen this error message when the "ToolsVersion" attribute of the "Project" element for your .csproj\.vbproj\etc... files isn't consistent across all projects that you're compiling. In my case one of my projects didn't have a "ToolsVersion" attribute and was - evidentally - defaulting to a different toolset to consume the "ResolveAssemblyReference.cache" than had produced it.

Coordinator
Mar 19, 2009 at 10:43 PM
Hi, 

Overlock, the error indicates an invalid project file, so I'm not sure what to say about that.  If the project builds locally, then I see no reason why DocProject couldn't build the same project file on the server, unless of course the project file is being modified somehow by an intermediate process.

I suggest examining the DocProject project file in TeamCity's working directory to see if it contains the IsDocProject="true" attribute in the VS user data section of the file.  If it does then perhaps the BuildDocProject MSBuild task is being passed a different project file path.

As for the build agent account, I was using my personal login credentials to run the service (actually, I found this out recenlty and it was certainly an accident).  But I don't think that's the problem based on DocProject's error message.  Also, I believe we're using Network Service account now and still no issues.

I recently upgraded to the latest version of TeamCity at my job and have experienced no issues with our existing build configurations.  So I think we can rule out a compatibility issue.

Thanks for the suggestion CodeMonster.  I assume that all of our ToolsVersion attributes are identical but I didn't check.

- Dave