MSBuild a .dbproj seems to run twice - msbuild

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.

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.

Set MSBuild Web Publish Property "ExcludeGeneratedDebugSymbol" from Command Line

I'm using NAnt to build my project and publish web site project(s). I'd like to include the PDBs in the resulting package. How can I set the ExcludeGeneratedDebugSymbol property from the command line when I execute msbuild?
I tried adding it to the list of parameters but I'm not seeing the PDBs still. My exec task looks like this:
<exec program="${MSBuildPath}" workingdir="${path::get-full-path(PublishWebProject.SourcePath)}\">
<!-- Don't show the logo. -->
<arg value="/nologo"/>
<!-- Build w/o Clean -->
<arg value="/t:Build"/>
<!-- Configuration, Output, Options, No Warnings -->
<arg value="/p:OutputPath=bin\;OutDir=${path::get-full-path(PublishWebProject.OutputPath)};Configuration=${Configuration};Platform=Any CPU;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;WarningLevel=0;RunCodeAnalysis=false;ExcludeGeneratedDebugSymbol=false"/>
<!-- Quiet -->
<arg value="/v:q"/>
<!-- Project Path -->
<arg value="${PublishWebProject.ProjectFileName}"/>
</exec>
And here is the actual call to MSBuild:
[exec] Starting 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe (/nologo /t:Build "/p:OutputPath=bin\;OutDir=D:\Projects\XYZ\Publish\Release-Production\CommonWeb\;Configuration=Release-Production;Platform=Any CPU;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;WarningLevel=0;RunCodeAnalysis=false;ExcludeGeneratedDebugSymbol=false" /v:q CommonWeb.csproj)' in 'D:\Projects\XYZ\Source\CommonWeb\'
Which would equate to:
D:\Projects\XYZ\Source\CommonWeb> C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /nologo /t:Build "/p:OutputPath=bin\;OutDir=D:\Projects\XYZ\Publish\Release-Production\CommonWeb\;Configuration=Release-Production;Platform=Any CPU;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False;WarningLevel=0;RunCodeAnalysis=false;ExcludeGeneratedDebugSymbol=false" /v:q CommonWeb.csproj
I've also tried setting the UseWPP_CopyWebApplication to false but this didn't help either.
Your project file contains information on output debug info. Try setting debug info to pdb-only:
<arg value="/debug:pdbonly" />

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

MSBuild failing for CruiseControl 1.6

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.

Using NAnt to build .NET 2.0 projects

I had a .NET 1.1 project, which I built in NAnt using the following snippet:
<property name="Refs.dir" value="Refs" readonly="false"/>
<property name="OAIDLLs.dir" value="OAI\bin\ServerDebug"/>
<solution
solutionfile="OAI\CC.OAI.sln"
configuration="ServerDebug"
outputdir="${OAIDLLs.dir}">
<assemblyfolders>
<include name="${Refs.dir}"/>
</assemblyfolders>
</solution>
Now someone has converted the project to .NET 2.0, and NAnt can't build it anymore.
It's easy enough to replace the solution tag with
<exec program="msbuild">
<arg value="OAI\CC.OAI.sln" />
</exec>
but I can't figure out how to pass value in assemblyfolders tag to msbuild. For those who don't know, assemblyfolders tag specifies the folder where the project should look for dependent assemblies.
One can specify additional properties with a /p switch. The properties that might be of interest here are:
AdditionalLibPaths - Specifies additional folders in which compilers should look for reference assemblies.
AssemblySearchPaths - A list of locations to search during build-time reference assembly resolution. The order in which paths appear in this list is meaningful because paths listed earlier takes precedence over later entries.
To specify additional properties using msbuild with the exec task:
<exec program="msbuild">
<arg value="OAI\CC.OAI.sln" />
<arg value="/p:AssemblySearchPaths=c:\path1" />
</exec>
As a side there is an msbuild task that is provided with NAntContrib.