I have a msbuild step where I will parse the xml file and get some filtered data. I need to pass the filtered data to Teamcity. Could this be done by teamcity variable or any other way?
<Target Name="ParseXmlAndReturn" >
<XmlPeek XmlInputPath ="$(ResultDir)\xmlfile.xml"
Query="<filter to get specific data from xml>">
<Output TaskParameter="Result" PropertyName="parsedxml"/>
</XmlPeek>
<Message Text="parsed xml is $(parsedxml)"/>
From the above task of msbuild, I need to pass parsedxml value to teamcity or assign a systemvariable to teamcity to the parsedvalue.
From the Teamcity 'Build Script Interaction' documentation:
By using a dedicated service message in your build script, you can
dynamically update some build parameters right from a build step, so
that the following build steps will run with a modified set of build
parameters.
##teamcity[setParameter name='ddd' value='fff']
So change the message tack to something like
<Message Text="##teamcity[setParameter name='ParsedXML' value='$(parsedxml)']"/>
Related
If I use the command line to run msbuild like this: msbuild myproject.dproj /t:Clean;Build /p:Config=Release /p:Platform=Win32 is there a way for the command line to get the value of where the actual exe of that command will be?
You should write a custom target to get that value.
First, add this target into the myproject.dproj:
<Target Name="GetOutputValue">
<Message Importance="high" Text="$(DCC_ExeOutput)"></Message>
</Target>
Then, directly use this command to invoke the GetOutputValue target to get that value.
msbuild myproject.dproj /t:GetOutputValue
I created a custom Task that executes after the build operation.
<Target Name="AfterBuild" />
<Target Name="MyTarget"
AfterTargets="AfterBuild">
<MyTask ... />
</Target>
QUESTION: Is it possible to execute the task, if the build operation was triggered, but did not perform, because there are no changes in the project / no need to build again?
In other words: I want to execute the task always at the end of the build process, even if the project was not built again.
UPDATE: Using AfterTargets="Build" or setting the property <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> does not help.
After triggering the Build process a second time, I only get the Output: Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped
Is it possible to execute the task, if the build operation was triggered, but did not perform, because there are no changes in the project / no need to build again?
If I understand you correctly, you can define this property in your project file:
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
Note: This method seems that Visual Studio is bypassing normal up-to-date checks of MSBuild and using some sort of custom check that is faster, but has a side effect of breaking customized build targets.
Update:
Not sure the reason why this method not work on your project, let me make the answer more detail:
Define the property in your project file:
Add the custom MSBuild task with some messages info.
Build the project, check the output(log file verbosity is Normal).
Build the project again, check the output again.
If I use AfterTargets="Build" instead of AfterBuild, the message is written to the Output window every time I build the solution (.NET Core Console App with a .NET Standard Class Libary).
<Target Name="MyAfterBuild" AfterTargets="Build">
<Message Importance="High" Text="Hello World!" />
</Target>
I'm trying to set which projects to package on TeamCity build run. To accomplish that I have a custom parameter setup in TeamCity build.
Parameter is set of project names, which is being prompted to be selected from predefined set of values (project names) when running the build.
For the sake of example let's say this custom parameter is:
ProjectToPackage: Project1, Project2, Project3
Later in the build step nuget pack I want to use this parameter to decide which projects to pack. So, in specification files I had:
trunk/*/*.csproj
Which is package all projects, which I want now to reflect custom parameter selection, something like this:
trunk/*/%ProjectToBuild%.csproj
Now this obviously won't work if multiple values are selected, as in cases when multiple values are selected parameter is "," separated string, e.g.if Project1 and Project2 selected, ProjectToPackage will be "Project1, Project2", as a result specification files selection would turn to:
trunk/*/Project1, Project2.csproj
Which of course fails.
So I'm looking for a way to be able to input project names to be packaged as a result of TeamCity build.
In order to accomplish this had to write some MSBuild script.
Considering there is custom parameter setup which lists all projects to be packaged with the name ProjectsToBuild, here's the MSBuild target that did the job:
<Target Name="Pack">
<ItemGroup>
<_SelectedProjectItem Include="$(ProjectsToBuild)" />
<ProjectsToPack Include="$(MSBuildProjectDirectory)\*\%(_SelectedProjectItem.Identity).csproj" />
</ItemGroup>
<Exec Command="$(PathToNuGetExe) pack %(ProjectsToPack.FullPath) -OutputDirectory $(OutDir) -IncludeReferencedProjects" />
</Target>
I am trying to import some props and targets file from a directory, which is a user-specified location. In order to determine this directory, I have some custom logic and I am trying to find a way to execute this in one of the props. I am unable to use the standard MSBUILD property functions to achieve this.
My end goal is to have a small UI that allows the user to specify this directory and the scope of this directory must be tied to a project i.e, there could be two different projects pointing to two different directory within a solution
What about calling your build script again after you have fiddled out all your requirements? Every call to the MSBuild task where you put $(MSBuildProjectFile) as your Projects value will call your build file again and that call will have a new copy of the environment.
<Project DefaultTargets="EntryPoint" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<Target Name="SetProperties">
<PropertyGroup>
<PropA>Something</PropA>
</PropertyGroup>
</Target>
<Target Name="EntryPoint">
<MSBuild
Projects="$(MSBuildProjectFile)"
Properties="Configuration=$(Configuration);OutputPath=$(OutputPath);"
Targets="SetProperties;EntryPoint"
Condition="$(PropA) == ''"/>
<Message
Text="Everything is set!"
Condition="$(PropA) != ''"/>
</Target>
</Project>
This setup can be easily extended to execute some Exec task logic and forwards that output to a new call to the entry point.
I want to use the VersionTask from the MSBuild Community Tasks to set the Revision calculation type. However, I am having difficulty understanding how to actually wire up the task within my csproj file.
The project has an AssemblyInfo.cs which has the following attribute defined:
[assembly: AssemblyVersion("3.2.5.*")]
What I want to do is over-ride the generation of the Revision number handling with my own custom handling.
I have put the customised Version task into the csproj file as follows:
<UsingTask TaskName="MyCo.Build.Tasks.Version" AssemblyFile="$(SolutionDir)\..\Build\.build\MyCo.Build.Tasks.dll" />
The actual task is then called as follows:
<Target Name="BeforeBuild">
<Message Text="Setting Revision Number to $(BuildNumber)" />
<MyCo.Build.Tasks.Version RevisionType="BuildServerNumber" Revision="$(BuildNumber)" /></Target>
I can see the target BeforeBuild being called because of the Message Task but the exe file still has the standard generated numbering as follows: File Version : 3.2.5.27547
I was expecting something like 3.2.5.111 (the build number passed into MSBuild as a parameter).
As the Version task is overriding the default handling of the '*' value for Revision I don't believe it is necessary to actually modify the AssemblyInfo.cs file.
Do I need to pass the output value from the Version task into an MSBuild parameter? Do I actually need to use the AssemblyVersion task to update the values in the file?
Obviously I am trying to avoid having to change the AssemblyInfo.cs, I just want to override the Version number handling.
Can someone advise please?
EDIT: I just found the following example of usage in the chm file from the installer which partly answers my question.
<Version BuildType="Automatic" RevisionType="Automatic" Major="1" Minor="3" >
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="Revision" />
</Version>
<Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>
However, when I run the build I can output the generated Assembly Version in a Message task but the exe file still has the default Revision as before
I got a resolution to this here: How to override the revision number
In the end I had to actually update the AssemblyInfo file for each project during the build. So on the build server (TeamCity) I placed the code I needed in the Microsoft.Common.targets file so that it wasn't required in each project ad then passed the release number and TeamCity build number to each build task.
The Revision is the number of days since 1/1/2000 when you set it to Automatic - you can supply your own "StartDate" if you want.