MSBuild failing for CruiseControl 1.6 - msbuild

G'day.
We've updated to ccnet 1.6 due to our TFS server being upgraded to 2010.
Within our ccnet.config we're executing a nant (0.9) build script that contains an MSBuild exec task.
Running MSBuild at command line with the parameters as specified by the nant script works okay, but for some reason when ccnet executes the MSBuild task via the nant script it fails with the following:
External Program Failed: C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe (return code was 128)
The nant exec task:
<property name="MSBuildPath" value="${framework.dir}\MSBuild.exe"/>
<exec program="${MSBuildPath}">
<arg line="${project.svds}.sln" />
<arg value="/t:Rebuild" />
<arg value="/p:Configuration=Release" />
<arg value="/p:Platform=x86" />
<arg value="/verbosity:normal" />
<arg line="/logger:'C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll'"/>
</exec>
Unfortunately no more is revealed and it's all rather cryptic.

128 There are no child processes to wait for.
Set MSBuildPath as below and try...
<property name="MSBuildPath" value="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" />
This thread might help you.
EDIT
Possibly this can be due to the service user account. It may be running as the Local System account. Changing the service account - via Control Panel / Administrative Tools / Services may help.

Related

Publishing ClickOnce application using NAnt and MSBuild

I'm attempting to publish a ClickOnce application using an MSBuild task within a NAnt script. The certificate is installed on the machine and I believe it's finding it, as it's now getting past an earlier problem of it not being able to get the certificate itself. However, it's now failing with the error:
[msbuild]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4512,5):
error MSB4044: The "SignFile" task was not given a value for the
required parameter "CertificateThumbprint"
The task currently is called like this:
<msbuild project="${SourceURL}/pathToProject/project.csproj" verbosity="Minimal">
<property name="Configuration" value="Client" />
<property name="Platform" value="AnyCPU" />
<arg value="/p:ApplicationVersion=${actualVersion}" />
<arg value="/p:CertificateThumbprint=XXX" />
<arg value="/p:ManifestCertificateThumbprint=XXX" />
<arg value="/t:publish" />
</msbuild>
How should I be passing the CertificateThumbprint into the publish task? I'm trying to avoid having to switch directly to using signtool or mage, since I'd like to keep it as close as possible to using Visual Studio directly as possible.

slqcmd query to restore database from disk do not work in ant exec task

I am trying whole evening in this sunday to make this one:
<exec executable="osql.exe" dir="${basedir}" failonerror="true">
<arg value="-U<user>" />
<arg value="-P<password>" />
<arg value="-S<server>" />
<arg value="-QRESTORE DATABASE <database> FROM DISK='<absolute_path_to_database_backup>.bak'" />
<arg value="-b" />
</exec>
As suspected, the
<arg line=""/>
also do not work. :(
into the same call, only using sqlcmd utility. Unforutinetly all I can get is the error message from ants executed sqlcmd that there is "Unexepcted attribute. Consult help -?".
[exec] Sqlcmd: '-Q"RESTORE DATABASE <database> FROM DISK='<absolute_path_to_database_backup>.bak'"': Unexpected argument. Enter '-?' for help.
BUILD FAILED
C:\SVN\Ver_trunk\Upgrade\build.xml:72: exec returned: 1
Actual names are replaced with <> brackes.
My PC software configuration:
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)
Apache Ant(TM) version 1.8.3 compiled on February 26 2012
Any help highly appreciated to make the correct syntax for this sqlcmd ... :)
Okay, here is the summary of the things I had to do to make it work ( at least from Jenkins :( ):
use <arg line="" /> syntax, not <arg value="" />
escape path by additional /
re-configure my workstation by suggestions here: http://social.msdn.microsoft.com/Forums/en-US/sqlsetupandupgrade/thread/3a2af602-75fe-4f9c-a795-733a228e7f30/

MSBuild a .dbproj seems to run twice

When we build our Visual Studio 2010 Database Project from the command line using msbuild.exe it can sometimes run twice from the same command line.
We call msbuild from a nAnt script, and just call the 'Build' target. Our database project is quite large so it can take about 4 mins to run through a single time. When it runs through twice our database build takes over 8 minutes.
Here is the exec section we use to call the build. It runs on a .sln file that only has a single .dbproj in it.
<exec program="${framework::get-tool-path('msbuild.exe')}" append="true" failonerror="true" verbose="true">
<arg value="${database.sln}" />
<arg value="/p:OutputPath=${build.output.database}" />
<arg value="/nologo" />
<arg value="/t:Build" />
<arg value="/p:Configuration=Release" />
<arg value="/p:WorkingDir="."" />
<arg value="/verbosity:normal" />
<arg value="/v:m" />
</exec>
The output we get looks like
Creating a model to represent the project...
Loading project references...
Loading project files...
Building the project model and resolving object interdependencies...
Validating the project model...
(x) problems have been detected.
[a list of warnings based on the db analysis]
The results are saved in (y).
Creating a model to represent the project...
Loading project references...
Loading project files...
Building the project model and resolving object interdependencies...
Validating the project model...
(x) problems have been detected.
[a list of warnings based on the db analysis]
The results are saved in (y).
Can anyone help as to why the target seems to be called twice (only sometimes - I haven't figured out why only sometimes). The script always runs on an empty folder structure so there is never a build output left over from a previous run of the build.
First of all try to change the output verbosity to diagnostic for MSBuild:
<arg value="/v:diag" />
And the same for the Ant script. I don't have experience with Ant , but you shpould know how to do it ;)
Hopefully you will find a reason in the diagnostic logs...
BTW:
You have duplicate command line options for MSBuild. Remove one arg from the following:
<arg value="/verbosity:normal" />
<arg value="/v:m" />
/v is abbreviation for /verbosity see MSDN for MSBuild command line options reference.

MSbuild 4.0 fail to compile .Net 3.5 project

I am using Msbuild 4.0.
In our project few solution are having .net 3.5 projects.
When i compile it through Visual studio it works. If i build the same using Msbuild it fails.
Following is the compilation issue:
error : Compilation failed. Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Exception from HRESULT: 0x80131515
Even i tried with changing
toolsversion to 3.5
through additionalproperties of item. [ I am using Msbuild task to build my solution]
Our Msbuild task looks like below.
<Target Name="BuildDotNETSolutions" Condition="'$(Group)' != ''" DependsOnTargets="Init;GetNextVersionNumber">
<!-- Complie solutions -->
<!-- Version property is useful for changing the Wix Msi version-->
<MSBuild Projects="#(Solution)" BuildInParallel="true"
Properties="Configuration=$(Configuration);PostbuildEvent=;Version=$(BuildNextVersionNumber)"
Condition="'%(Solution.Group)' == '$(Group)' And '%(Solution.Type)' == 'DotNET' And '%(Solution.IsRebuild)'=='$(IsRebuild)'">
<Output
TaskParameter="TargetOutputs"
ItemName="BuildOutputs" />
</MSBuild>
We are passing solutions through properties file like below
<Solution Include="$(Implementation)\MultiEvent.csproj;">
<Group>Event</Group>
<AdditionalProperties>
ReferencePath=$(Implementation)\References;
ToolsVersion=3.5;
</AdditionalProperties>
<IsRebuild>True</IsRebuild>
<Type>DotNET</Type>
</Solution>
I don't know if you happen to have any script-runner that runs MSBuild. Personnally, I'm using NAnt and everything is working fine. I've read (somewhere) that MSBuild sometimes do stupid things and by adding the property "TrackFileAccess" and set it to "false" helps a lot. In my case, it fixed the problem.
If it can be of any help, I've included my NAnt build task. I hope it can be useful to you.
<!--*******************************************************************************
Runs MSBuild to build the project solution
Arguments:
${MSBuild.exe}: Path to MSBuild.exe
${project.solution}: the solution name to build
${buildconfiguration}: The build configuration to trigger the build
${build.dir} : The directory where to put builded files
********************************************************************************-->
<target name="run.msbuild" description="Rebuilds a given solution file">
<echo message="Rebuilding Solution ${project.solution}" />
<echo>${MSBuild.exe}</echo>
<exec program="${MSBuild.exe}">
<arg value="${project.solution}"/>
<arg line="/property:SignAssembly=${project.sign},AssemblyOriginatorKeyFile=${project::get-base-directory()}\${project.signature.file}" />
<arg line="/property:OutDir=${build.dir}" />
<arg line="/property:TrackFileAccess=false" />
<arg line="/property:DebugType=${debug.type}" />
<arg line="/property:Platform="Any CPU"" />
<arg line="/nologo" />
<arg line="/verbosity:minimal" />
<arg line="/property:Configuration=${buildconfiguration}"/>
</exec>
in the case of a Development build, I set the following params :
<property name="buildconfiguration" value="Debug"/>
<property name="debug.type" value="full" />

NAnt <msbuild> custom output directory

I'm new to NAnt and have been able to create a <target> which
1) Deletes any code from the current folder
2) Exports fresh code from SVN
3) Builds the code in the default directory which is the PrecompiledWeb folder (its a web app)
Here it is:
<target name="export" description="export code from svn">
<delete dir="${Delete.Dir}"></delete>
<exec program="svn" commandline="export ${MySVN.Repos} ${MySVN.Dest}" />
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
</msbuild>
</target>
I want to specify a custom output directory (other than "PrecompiledWeb"). Is this possible and could you please show me the necessary tag/property?
Thank you!
EDIT
Thanks to Scott and Si, I'm getting closer to a solution, but I still don't have anything that works. There comments led me to this article on MSBuild's Output Path Property. Using their code:
<?xml version="1.0"?>
<project name="test" default="build" basedir="." xmlns="http://nant.sf.net/schemas/nant-0.84.win32.net-1.0.xsd">
<target name="build">
<exec program="${framework::get-framework-directory('net-3.5')}/msbuild.exe">
<arg value="${Full.Path}\Code\MySolution.sln" />
<arg value="/p:OutputPath=${Full.Path}\Output\" />
</exec>
</target>
</project>
This will sucessfully run; however, in my solution which contains a web site and a class library, it publishes the class library dll to the specified output path, but it still publishes the actual web site to the default PrecompiledWeb folder.
Does anyone have any suggestions for how to change the PrecompiledWeb folder path from NAnt?
Thanks again to everyone who's helped!
Edit 2 Final Solution
Here is what I finally was able to get working (updated for .net 4):
<exec program="${framework::get-framework-directory('net-4.0')}/msbuild.exe">
<arg value="${Full.Path}\Code\MySolution.sln" />
<arg value="/t:Rebuild" />
<arg value="/t:ResolveReferences" />
<arg value="/t:_CopyWebApplication" />
<arg value="/p:OutDir=${Build.Output}bin\" />
<arg value="/p:WebProjectOutputDir=${Build.Output}" />
<arg value="/p:Configuration=Release" />
</exec>
One can specify and override some of properties for msbuild. In order to specify the output directory, override the OutputDir property.
<target name="export" description="export code from svn">
<delete dir="${Delete.Dir}" />
<exec program="svn" commandline="export ${MySVN.Repos} ${MySVN.Dest}" />
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
<property name="OutputDir" value="${Output.Dir}"/>
</msbuild>
</target>
Just had a quick peek at a project, does OutputPath instead of OutputDir help?
Another option might be a web deployment project, which I like because it calls aspnet_compiler as well as the C# compiler, so it picks up issues which you may otherwise miss until deployment.
A build script for one of our projects uses this command to publish a web application:
msbuild.exe /t:_CopyWebApplication /p:Configuration=Release /p:OutDir=.\..\published\ /p:WebProjectOutputDir=.\..\published
(The current directory is set to the web app's project directory at this point, which is why no .csproj file is specified. The entire solution has already been rebuilt earlier in the script.)
By the sound of it, WebProjectOutputDir might be the property you need.
/t:_CopyWebApplication may also be important. I've not used NAnt so I don't know if you can pass this parameter with the msbuild task. You may need to use an exec task, like in this example: http://www.netomatix.com/development/wapwithnant.aspx. This example appears to rebuild and copy all in one go.
When using the task, the correct property name is OutDir, not OutputDir:
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
<property name="OutDir" value="${Output.Dir}"/>
</msbuild>
A source of confusion is that you're blending two distinct build systems. Your NAnt target is delegating all the work of figuring out how to publish your web application to the solution file, hence by extension to the csproj files it references.
csproj files are MsBuild files, so you should probably look there for how to direct your project output. This post by dave^2 might be helpful on that issue.
You can publish your web application wherever you want using NAnt, provided it's doing the publishing. You can do the same with MsBuild. The cause of your quandary is that NAnt is not doing the publishing in this case, and you're letting the csproj file determine the location of your web directory. So either bypass the csproj file and have NAnt (or MsBuild) publish the code; or modify the csproj file to publish the web application where you want; or make a second location for your web application and publish it there as well using your build tool.
AFAIK, those options are exhaustive.
Hmm, don't know how to do it with MSBuild in Nant, but using NAnt, I've done it previously like this:
<solution solutionfile="${build.dir}\solution.sln">
<webmap>
<map url="http://localhost/somdir/project.csproj"
path="c:\inetpub\wwwroot\somelocaldir" />
<webmap>
</solution>
But then, you're using the NAnt 'solution' task offcourse instead of using MSBuild directly.
edit:
I'm also having a look at some msbuild options;
If you set OutDir & OutputPath to the same value, what happens ?
Try something like this:
<property name="nant.settings.currentframework" value="net-3.5"/>
<msbuild project="${Solution.Filename}">
<property name="Configuration" value="Release"/>
<property name="OutDir" value="${Full.Path}\Output\\"/>
<property name="WebProjectOutputDir" value="${Full.Path}\Output\Web\\"/>
</msbuild>