how to run msbuild script through cruise control - msbuild

I am getting execption when i am running cruise control by iis or cctray and below is ccnet.config.i wanted to run my scrip through cruise control .please let me know how to relove this issue
<project name="Visteon">
<webURL>http://localhost/ccnet/</webURL>
<triggers>
<intervalTrigger seconds="110" buildCondition="ForceBuild" />
</triggers>
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
</executable>
<workingDirectory>E:\workingfolder_123</workingDirectory>
<buildArgs>E:\CCnet.xml /p:Configuration=release</buildArgs>
<timeout>1800</timeout>
<!-- 30 minutes -->
<logger>C:\Program Files\CruiseControl.NET\server\
ThoughtWorks.CruiseControl.MSBuild.dll</logger>
</msbuild>
</tasks>
</project>
</cruisecontrol>
my scripts is like this
<Target Name="GetSource">
<Message Text="Checking out trunk into $(SourceDirectory)" />
<SvnCheckout RepositoryPath="$(SvnCheckoutPath)"
LocalPath="$(CheckOutPath)"
UserName="aa"
Password="aa">
<Output TaskParameter="Revision" PropertyName="Revision" />
</SvnCheckout>
</Target>
<Target Name="Build" DependsOnTargets="GetSource;Clean;" />
<Target Name="Clean">
<!-- Clean, then rebuild entire solution -->
<MSBuild Projects="$(CheckOutPath)\SUPPLIER_SOFTWARE.sln" Targets="Clean;Rebuild" />
</Target>

Try using the CruiseControl Template below
<project name="MyCodeFolder Project" queue="MyQueue" queuePriority="1">
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>D:\Projects\MyCodeFolder</workingDirectory>
<projectFile>CCnet.xml</projectFile>
<buildArgs>/noconsolelogger /nologo /p:Configuration=Release</buildArgs>
<targets>
</targets>
<timeout>4800</timeout>
</msbuild>
</tasks>
As for the build script you will need the root to have Project node and set default target name main as the entry point. Please see below:
<Project DefaultTargets="Main">
<Target Name="Main">
//Do Something
</Target>
</Project>

You are missing project file tag e.g.
<projectFile>your_msbuild_script-here</projectFile>
http://build.sharpdevelop.net/ccnet/doc/CCNET/MsBuild%20Task.html
I'm also not sure what exactly E:\CCnet.xml is. If this is your msbuild file, put it
inside <projectFile/> and try again.
I hope that helps.

Related

Add output or transfer data from child to parent project

I use msbuild in main.proj to build a project like this:
<MSBuild Projects="outs.proj" Targets="Build">
<Output ItemName="CustomOutputs" TaskParameter="TargetOutputs"/>
</MSBuild>
Inside outs.proj I have a custom Target, I need to add an output from this target to get .dll,.pdb,..., and .mycustomfiles
How can I send data from child project to parent project ?
Thanks in advance for your help.
I'd recommend you simply Import the dependant project, however the basic scenario you described can be achieved with Target's Outputs or Returns and corresponding Output's TargetOutputs although there are few caveats as it's designed for incremental builds and not as a data transfer object.
foo.build
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Foo1">
<MSBuild Projects="bar.build">
<Output TaskParameter="TargetOutputs" ItemName="Bar" />
</MSBuild>
<Message Text="%(Bar.Identity)" />
</Target>
<Import Project="bar.build" />
<Target Name="Foo2" DependsOnTargets="Bar">
<Message Text="%(Bar.Identity)" />
</Target>
</Project>
bar.build
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Bar" Outputs="#(Bar)">
<ItemGroup>
<Bar Include="**\*.dll" />
</ItemGroup>
</Target>
</Project>

how to set msbuild script path in ccnet.config using cruise control.net

I am getting below execption when i am trying to run script using cruise control.please look into my code and let me know where i am doing mistake
<build date="2013-07-02 16:38:56" buildtime="00:00:00" error="true" buildcondition="ForceBuild">MSBUILD : error MSB1008: Only one project can be specified.
Switch: e:\mybuild.xml
ccnet.config file
<cruisecontrol>
<project name="Visteon">
<webURL>http://localhost:333/ccnet/</webURL>
<triggers>
<intervalTrigger seconds="110" buildCondition="ForceBuild" />
</triggers>
<tasks>
<msbuild>
<executable>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>E:\workingproject_5145</workingDirectory>
<projectFile>myproject.sln</projectFile>
<buildArgs>msbuild e:\mybuild.xml /t:Buildrun</buildArgs>
<timeout>120</timeout>
<logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
</tasks>
</project>
</cruisecontrol>
my scriptsis defined in mybuild.xml which is below mentioned
<Target Name="GetSource">
<Message Text="Checking out trunk into $(SourceDirectory)" />
<SvnCheckout RepositoryPath="$(SvnCheckoutPath)"
LocalPath="$(CheckOutPath)"
UserName="aa"
Password="aa">
<Output TaskParameter="Revision" PropertyName="Revision" />
</SvnCheckout>
</Target>
<Target Name="Buildrun" DependsOnTargets="GetSource;Clean;" />
<Target Name="Clean">
<!-- Clean, then rebuild entire solution -->
<MSBuild Projects="$(CheckOutPath)\myproject.sln" Targets="Clean;Rebuild" />
</Target>
Your projectFile should be the xml file...(that is a .msbuild file)
I think this is what you want.
<projectFile>mybuild.xml</projectFile>
<buildArgs>/t:Buildrun</buildArgs>
LONG VERSION:
<executable>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>E:\workingproject_5145</workingDirectory>
<projectFile>myproject.sln</projectFile>
<buildArgs>msbuild e:\mybuild.xml /t:Buildrun</buildArgs>
So it's gonna concatenate these values
$executable $workingDirectory $projectFile $buildArgs
So you get something like this:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe E:\workingproject_5145\myproject.sln msbuild e:\mybuild.xml /t:Buildrun
which is not what you want.
If you make the values like this:
<executable>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>E:\workingproject_5145</workingDirectory>
<projectFile>mybuild.xml</projectFile>
<buildArgs>/t:Buildrun</buildArgs>
You'll get something like this:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe "E:\workingproject_5145\mybuild.xml" /t:Buildrun

Calling MSbuild Publish

Is it possible to call MSbuild publish during build or in pre-buildevent or in post-buildevent? I'm trying to publish two of the web projects from a solution. I'm using file system publishing.Requirement here is , building solution should take care of publish those two web projects. Can any one please suggest ?
I wouldn't put too much deploy logic in a post-build event. It becomes "fragile".
Create a separate .msbuild file, and do the "extra" logic in it, instead of messing too much with the .csproj file.
Below is a basic example.
Place the xml below in an file call "MyBuildAndDeploy.msbuild", put it in the same folder as your .sln (or .csproj) file, and then use
msbuild.exe "MyBuildAndDeploy.msbuild" from the command line.
So below is a basic example of building the primary solution and then copying the files somewhere.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapper">
<PropertyGroup>
<!-- Always declare some kind of "base directory" and then work off of that in the majority of cases -->
<WorkingCheckout>.</WorkingCheckout>
<BuildResultsRootFolder>$(WorkingCheckout)\..\BuildResults</BuildResultsRootFolder>
</PropertyGroup>
<Target Name="AllTargetsWrapper">
<CallTarget Targets="BuildSolution" />
<CallTarget Targets="CopyBuildOutputFiles" />
</Target>
<Target Name="BuildSolution">
<MSBuild Projects="$(WorkingCheckout)\MySuperCoolSolution.sln" Targets="Build" Properties="Configuration=$(Configuration)">
<Output TaskParameter="TargetOutputs" ItemName="TargetOutputsItemName"/>
</MSBuild>
<Message Text="BuildSolution completed" />
</Target>
<Target Name="CopyBuildOutputFiles">
<MakeDir Directories="$(BuildResultsRootFolder)\$(Configuration)" Condition="!Exists('$(BuildResultsRootFolder)\$(Configuration)\')"/>
<ItemGroup>
<BuildOutputFilesExcludeFiles Include="$(WorkingCheckout)\**\*.doesnotexist" />
<BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.dll" Exclude="#(BuildOutputFilesExcludeFiles)" />
<BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.exe" Exclude="#(BuildOutputFilesExcludeFiles)" />
<BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.config" Exclude="#(BuildOutputFilesExcludeFiles)" />
<BuildOutputFilesIncludeFiles Include="$(WorkingCheckout)\**\*.pdb" Exclude="#(BuildOutputFilesExcludeFiles)" />
</ItemGroup>
<Copy SourceFiles="#(BuildOutputFilesIncludeFiles)"
DestinationFolder="$(BuildResultsRootFolder)\$(Configuration)\"/>
</Target>
</Project>

MSBuild and creating ZIP files

Here is my build script:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<!-- Path where the solution file is located (.sln) -->
<ProjectPath>W:\Demo</ProjectPath>
<!-- Location of compiled files -->
<DebugPath>W:\Demo\bin\Debug</DebugPath>
<ReleasePath>W:\Demo\bin\Release</ReleasePath>
<!-- Name of the solution to be compiled without the .sln extension --> <ProjectSolutionName>DemoTool</ProjectSolutionName>
<!-- Path where the nightly zip file will be copyd -->
<NightlyBuildPath>W:\Nightly_Builds\Demo</NightlyBuildPath>
<!-- Name of the nighly zip file (YYYYMMDD_NightlyZipName.zip, date added automatically) -->
<NightlyZipName>Demo</NightlyZipName>
</PropertyGroup>
<ItemGroup>
<!-- All files and folders from ./bin/Debug or ./bin/Release what will be added to the nightly zip -->
<DebugApplicationFiles Include="$(DebugPath)\**\*.*" Exclude="$(DebugPath)\*vshost.exe*" />
<ReleaseApplicationFiles Include="$(ReleasePath)\**\*.*" Exclude="$(ReleasePath)\*vshost.exe*" />
</ItemGroup>
<Target Name="DebugBuild">
<Message Text="Building $(ProjectSolutionName) Debug Build" />
<MSBuild Projects="$(ProjectPath)\$(ProjectSolutionName).sln" Targets="Clean" Properties="Configuration=Debug"/>
<MSBuild Projects="$(ProjectPath)\$(ProjectSolutionName).sln" Targets="Build" Properties="Configuration=Debug"/>
<Message Text="$(ProjectSolutionName) Debug Build Complete!" />
<CallTarget Targets="CreateNightlyZip" />
</Target>
<Target Name="CreateNightlyZip">
<PropertyGroup>
<StringDate>$([System.DateTime]::Now.ToString('yyyyMMdd'))</StringDate>
</PropertyGroup>
<MakeDir Directories="$(NightlyBuildPath)"/>
<Zip Files="#(DebugApplicationFiles)"
WorkingDirectory="$(DebugPath)"
ZipFileName="$(NightlyBuildPath)\$(StringDate)_$(NightlyZipName).zip"
ZipLevel="9" />
</Target>
</Project>
My script works perfectly, only there is one strange problem. When i build a project first time and there is no \bin\Debug folder and its created during the build, but the ZIP file still comes empty. Running the build script second time when the \bin\Debug folder is now in place with builded files then the file are added to the ZIP.
What could be the problem that running script first time the ZIP file is empty?
The problem is in the DebugApplicationFiles item collection. It is created before the build is invoked. Move the DebugApplicationFiles into CreateNightlyZip target. Update your script this way:
<Target Name="CreateNightlyZip">
<PropertyGroup>
<StringDate>$([System.DateTime]::Now.ToString('yyyyMMdd'))</StringDate>
</PropertyGroup>
<ItemGroup>
<DebugApplicationFiles Include="$(DebugPath)\**\*.*" Exclude="$(DebugPath)\*vshost.exe*" />
</ItemGroup>
<MakeDir Directories="$(NightlyBuildPath)"/>
<Zip Files="#(DebugApplicationFiles)"
WorkingDirectory="$(DebugPath)"
ZipFileName="$(NightlyBuildPath)\$(StringDate)_$(NightlyZipName).zip"
ZipLevel="9" />
</Target>
If powershell 5.0 or greater is available, you could use powershell command directly.
<Target Name="Zip" BeforeTargets="AfterBuild">
<ItemGroup>
<ZipFiles Include="$(OutDir)release\file1.exe" />
<ZipFiles Include="$(OutDir)release\file2.exe" />
</ItemGroup>
<Exec Command="PowerShell -command Compress-Archive #(ZipFiles, ',') $(OutDir)release\zippedfiles.zip" />
</Target>
Should you wish to zip a whole folder for 'xcopy deploy', since MSBuild 15.8 there is a simple way - the ZipDirectory build task.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="ZipOutputPath" AfterTargets="Build">
<ZipDirectory
SourceDirectory="$(OutputPath)"
DestinationFile="$(OutputPath)\..\$(AssemblyName).zip"
Overwrite=="true" />
</Target>
</Project>
[1] https://learn.microsoft.com/en-us/visualstudio/msbuild/zipdirectory-task?view=vs-2019

Updating Assembly information with MSBuild failing

All
i am trying to automatically update the assembly information of a project using AssemblyInfo task, before build however the target appears to do nothing (no failure/error) just no update/creation
Below is the build.proj file I am using (obviously some contents altered)
Can anyone help?
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.targets"/>
<PropertyGroup>
<Major>1</Major>
<Minor>0</Minor>
<Build>0</Build>
<Revision>0</Revision>
</PropertyGroup>
<PropertyGroup>
<BuildDir>C:\svn\Infrastructure</BuildDir>
</PropertyGroup>
<ItemGroup>
<SolutionsToBuild Include="Infrastructure.sln"/>
</ItemGroup>
<Target Name="Build" DependsOnTargets="ChangeDataAccessAssemblyInfo">
<RemoveDir Directories="$(BuildDir)\Builds" Condition="Exists('$(BuildDir)\Builds')" />
<MSBuild Projects="#(SolutionsToBuild)" Properties="Configuration=Debug" Targets="Rebuild" />
</Target>
<ItemGroup>
<TestAssemblies Include="Build\Logging\Logging.UnitTests.dll" />
</ItemGroup>
<!--<UsingTask TaskName="NUnit" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)" />
<Target Name="Test" DependsOnTargets="Build">
<NUnit NUnitVersion="NUnit-2.4.6" Assemblies="#(TestAssemblies)" />
</Target>-->
<Target Name="ChangeDataAccessAssemblyInfo" >
<Message Text="Writing ChangeDataAccessAssemblyInfo file for 1"/>
<Message Text="Will update $(BuildDir)\DataAccess\My Project\AssemblyInfo.vb" />
<AssemblyInfo CodeLanguage="VB"
OutputFile="$(BuildDir)\DataAccess\My Project\AssemblyInfo_new.vb"
AssemblyTitle="Data Access Layer"
AssemblyDescription="Message1"
AssemblyCompany="http://somewebiste"
AssemblyProduct="the project"
AssemblyCopyright="Copyright notice"
ComVisible="true"
CLSCompliant="true"
Guid="hjhjhkoi-9898989"
AssemblyVersion="$(Major).$(Minor).1.1"
AssemblyFileVersion="$(Major).$(Minor).5.7"
Condition="$(Revision) != '0' "
ContinueOnError="false" />
<Message Text="Updated Assembly File Info"
ContinueOnError="false"/>
</Target>
</Project>
I think you are missing the specification of the AssemblyInfoFiles attribute on your AssemblyInfo task. Here's how it looks on a project I'm working on...
<Target Name="AfterGet">
<Message Text="In After Get"/>
<CreateItem Include="$(SolutionRoot)\Source\SomeProject\My Project\AssemblyInfo.vb">
<Output ItemName="AssemblyInfoFiles" TaskParameter="Include"/>
</CreateItem>
<Attrib Files="#(AssemblyInfoFiles)"
ReadOnly="false"/>
<AssemblyInfo AssemblyInfoFiles="#(AssemblyInfoFiles)"
AssemblyDescription="$(LabelName)">
</AssemblyInfo>
</Target>
What we're doing is first using to create a property that contains the name of the file we'll be updating. We have to do this via createItem because when we start the build the file doesn't exist (and that is when MSBuild evaluates the and definitions in your build file.
We then take the readonly bit off the file.
Finally we invoke the AssemblyInfo task passing it the file(s) to update and a custom assembly name that we want to give it (in this case we put the TFS build label into the Assembly Description field so that we can easily tell which team build the assembly came from.