The Version is 1.0.0.0 even though both the file version and product version are defined in the DLL and display correctly when I view its properties in Windows 7. Any suggestions?
<Target Name="TestingAssemblyIdentity">
<GetAssemblyIdentity AssemblyFiles="MyCSharp.dll">
<Output TaskParameter="Assemblies" ItemName="assemblyInfo"/>
</GetAssemblyIdentity>
<Message Text="GetAssemblyIdentity Version is %(assemblyInfo.Version)" />
</Target>
The GetAssemlyIdentity task returns the assembly version (AssemblyVersionAttribute), not the file or product version. The later are not part of the assembly's identity.
Note that assembly version and assembly file/product version serve different purposes.
See here for a possible way to read the file version from within msbuild.
Related
Step 1:
Do the edit for following to the *.*proj files
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.-->
<Target Name="BeforeBuild">
<Version VersionFile="..\VersionInfo.txt" RevisionType="Increment">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="Revision" />
</Version>
<AssemblyInfo CodeLanguage="CS" OutputFile=".\Properties\AssemblyVersion.cs" AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)" AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" />
</Target>
<!--
<Target Name="AfterBuild">
</Target>
-->
Step 2:
Remove the AssemblyVersion number, and AssemblyFileVersion from the AssemblyInfo.cs
Step 3:
Create a file called VersionInfo.text outside where the sln resides.
Step 3:
Include the AssemblyVersionNumber.cs into the project's
Step 4:
Issue a MSBuild, Works fine on local machine, but not on the build server.
DevMachine: (32 bit)
C:\SVNHome\branches\MyGreatProject-II>msbuild -ver
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3643]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
BuildServer:
D:\SVNHome\branches\source\MyGreatProject-II>%windir%\Microsoft.NET\Framework64\v3.5\msbuild
-ver
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.4234]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Error Message given on the build server is not helping.
Properties\AssemblyInfo.cs: error CS1730: Assembly and module
attributes must precede all other elements defined in a file except
using clauses and extern alias declarations
Its my bad, Went on to the Server,
Undo all checkouts on the build Server
Force a build, then it worked fine.
Thank you Jessehouwing. That was it.
I'm currently moving my project to Visual Studio 2012 and start using nuget.
So I'll use the "NUnit Runners" nuget package instead of a nunit library.
The problem being that nuget creates folders with the package version. For example, NUnit Runners is inside the folder:
src\packages\NUnit.Runners.2.6.1\
Until now, Nunit was inside my lib\NUnit folder.
So, inside my MSBuild file, I was executing the tests by specifying the path:
<PropertyGroup>
<NUnitFolder>$(MSBuildProjectDirectory)\lib\NUnit</NUnitFolder>
</PropertyGroup>
<NUnit Assemblies="..." ToolPath="$(NUnitFolder)" />
But I don't want to have to specify a version number inside my msbuild task, that I would have to update everytime NUnit.Runners is updated.
I tried to play around with CreateProperty, but it doesn't seem to accept wildcards.
I also tried ItemGroup, but it works for a list of files, not a folder.
In the end, instead of trying to create a property with a wildcard, in my case I retrieved the version of NUnit.Runners from the packages.config file.
I now have a Target like this:
<Target Name="GetNUnitFolder">
<!-- Retrieves the version of NUnit.Runners from the solution's packages.config file -->
<XmlRead Namespace=""
XPath="packages/package[#id='NUnit.Runners']/#version"
XmlFileName="$(MSBuildProjectDirectory)\src\.nuget\packages.config">
<Output TaskParameter="Value" PropertyName="NUnitVersion" />
</XmlRead>
<CreateProperty Value="$(MSBuildProjectDirectory)\src\packages\NUnit.Runners.$(NUnitVersion)\tools">
<Output TaskParameter="Value" PropertyName="NUnitFolder" />
</CreateProperty>
</Target>
Note: to be able to use XmlRead, you need the MSBuildCommunityTasks.
And once I have the version, I rebuild my NUnitFolder property.
I am trying to automate the process for setting the Version for all DLL's, after spending some time I came to know the AssemblyInfo Task with which it can most likely be achieved.
So I went ahead and installed it, specifically version 1.0.51130.0.
After Installing, I manually added the Import Tag (by unloading the each project) of AssemblyInfoTask in .cspoj files (the solution has more than 35 proj files).
<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.Targets"/>
Next I modified the Microsoft.VersionNUmber.Target file which will be installed in path: C:\Program Files\MSBuild\Microsoft\AssemblyInfoTask, and I modified the following section:
<!-- Properties for controlling the Assembly Version -->
<PropertyGroup>
<AssemblyMajorVersion>4</AssemblyMajorVersion>
<AssemblyMinorVersion>0</AssemblyMinorVersion>
<AssemblyBuildNumber></AssemblyBuildNumber>
<AssemblyRevision></AssemblyRevision>
<AssemblyBuildNumberType>DateString</AssemblyBuildNumberType>
<AssemblyBuildNumberFormat>01MMdd</AssemblyBuildNumberFormat>
<AssemblyRevisionType>AutoIncrement</AssemblyRevisionType>
<AssemblyRevisionFormat>00</AssemblyRevisionFormat>
</PropertyGroup>
<!-- Properties for controlling the Assembly File Version -->
<PropertyGroup>
<AssemblyFileMajorVersion>4</AssemblyFileMajorVersion>
<AssemblyFileMinorVersion>0</AssemblyFileMinorVersion>
<AssemblyFileBuildNumber></AssemblyFileBuildNumber>
<AssemblyFileRevision></AssemblyFileRevision>
<AssemblyFileBuildNumberType>DateString</AssemblyFileBuildNumberType>
<AssemblyFileBuildNumberFormat>01MMdd</AssemblyFileBuildNumberFormat>
<AssemblyFileRevisionType>AutoIncrement</AssemblyFileRevisionType>
<AssemblyFileRevisionFormat>00</AssemblyFileRevisionFormat>
</PropertyGroup>
Next I set the assemblyInfo.cs file's version to 1.0.0.0 in every project. Finally I saved and close it, reopened solution, and built. It works like a champ!
Now what want is to customize the Version to 4.0.1053.1 where 10 is the part of year indicator which is 2010 and 53 denotes the week number, at last 1 denotes revision number.
How to achieve this using the AssemblyInfo Task? I came across several posts that a new version of AssemblyInfo Task is available in Build Extension Pack.
I have installed the MSBuild Extension Pack December 2010 and its version is MSBuild Extension Pack 4.0.2.0 Installer
First.. use a globalassemblyinfo.cs that is linked from each project.
Add its as linked file to each project.
This means you update one file, not 30+ assemblyinfo files...then:
use MSBuild.Community.Tasks....
Then call
<AssemblyInfo CodeLanguage="CS"
OutputFile="$(VersionFile)"
AssemblyCompany="Company"
AssemblyProduct="Product"
AssemblyCopyright="Copyright © Company 2011"
ComVisible="false"
AssemblyVersion="$(BUILD_NUMBER)"
AssemblyFileVersion="$(BUILD_NUMBER)" />
Assuming you have something like:
<Import Project=".\tasks\MSBuild.Community.Tasks.Targets"/>
I do this in Jenkins by having a package build that is parameterised using the List Subversion Tags parameter type. The Subversion tag must follow the version number format (major.minor.revision.build), e.g. tags/2.0.0.1. The tag name is then assigned to a Jenkins parameter, e.g. $VERSION becomes 2.0.0.1
I use the WriteLinesToFile msbuild task to write out the assembly attribute to a second file alongside the PropertyInfo.cs called VersionInfo.cs. As checked in to source control, this just contains a default version number:
// Do not change this. The version is set on package builds only by setting the AsmVersion MSBuild property
[assembly: System.Reflection.AssemblyVersion("0.0.0.0")]
The package build on the build server passes in the version via the AsmVersion parameter:
/p:AsmVersion=$VERSION
The .csproj file is modified to have a BeforeBuild target (Visual Studio creates a commented out one for you):
<Target Name="BeforeBuild">
<WriteLinesToFile
Condition=" '$(AsmVersion)' != '' " File="Properties\VersionInfo.cs"
Overwrite="True"
Lines="[assembly: System.Reflection.AssemblyVersion("$(AsmVersion)")] // Generated by build" />
</Target>
When building in Visual Studio, or without passing in the AsmVersion, your assembly will have a default version of 0.0.0.0. When building in the package build, you will get your desired build number.
As #bruceboughton proposed, you can easily generate a version assembly file during compilation without using MSBuild.Community.Tasks library:
<PropertyGroup>
<Version>0.0.0</Version>
<InformationalVersion>0.0.0-dev~commithash</InformationalVersion>
<VersionFileName>$(BaseIntermediateOutputPath)Version.cs</VersionFileName>
</PropertyGroup>
<Target Name="GenerateVersionFile" BeforeTargets="BeforeBuild">
<WriteLinesToFile
File="$(VersionFileName)"
Overwrite="True"
Lines="
[assembly: System.Reflection.AssemblyVersion("$(Version)")]
[assembly: System.Reflection.AssemblyFileVersion("$(Version)")]
[assembly: System.Reflection.AssemblyInformationalVersion("$(InformationalVersion)")]" />
<ItemGroup>
<Compile Include="$(VersionFileName)" />
</ItemGroup>
</Target>
Remove definitions of the parameters you specify in the generated file from Properties\AssemblyInfo.cs file.
After that you can specify version by adding a parameter to the msbuild:
msbuild /property:Version=1.2.3 /property:InformationalVersion=1.2.3-dev~commithash .\SolutionFile.sln
Update for .NET Core style .csproj files: If you've come upon this question after having transitioned to the new .csproj format used by .NET Core, you can just set the Version property (no need to to bother with MSBuild tasks).
How I finally got this to work MSBuild version 12 (VS 2013).
Used Nuget to get MSBuildTasks Community package
Edited my .csproj file and added a path to the import the package:
<Import Project="..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.targets" Condition="Exists('..\packages\MSBuildTasks.1.5.0.235\build\MSBuildTasks.target')"/>
Figured out the Regex to change just the Revision number in the AssemblyInfo.cs file:
(?<=AssemblyFileVersion\("[0-9]\.[0-9]\.[0-9]\.)(\*)
which is not XML compatible, so has to be changed to:
(?<=AssemblyFileVersion\("[0-9]\.[0-9]\.[0-9]\.)(\*)
Uncommented the <Target Name="BeforeBuild"> section and added the following:
<Target Name="BeforeBuild">
<FileUpdate Files="properties\AssemblyInfo.cs"
Regex="(?<=AssemblyFileVersion\("[0-9]\.[0-9]\.[0-9]\.)(\*)"
ReplacementText="$(Revision)" />
</Target>
When running MSBuild added the "Revision" property to the command line e.g.
msbuild.exe myProject.csproj /t:Build /p:Configuration=Release;Revision=12345
I'm trying to build a MonoTouch project using xbuild (on a Mac, clearly). Here's my xbuild project:
<Project DefaultTargets="Application" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ApplicationProjectFilePath>..\TestApp\TestApp.csproj</ApplicationProjectFilePath>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<MonoTouchReferencePath>/Developer/MonoTouch/usr/lib/mono/2.1/</MonoTouchReferencePath>
</PropertyGroup>
<Target Name="Application">
<MSBuild Projects="$(ApplicationProjectFilePath)" Targets="Rebuild" Properties="Configuration=AdHoc;Platform=iPhone;ReferencePath=$(MonoTouchReferencePath)" ToolsVersion="3.5"/>
</Target>
</Project>
When I run this, I get the following warning:
/Library/Frameworks/Mono.framework/Versions/2.6.7/lib/mono/3.5/Microsoft.Common.targets: warning : Found a conflict between : 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' and 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Using 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' reference.
How can I have xbuild reference v3.5 of the framework? As you'll see from the script, I've tried a number of approachs, none of which seem to be working.
[Also, I'm not sure why I have to explicitly reference the monotouch.dll library - given that it's referenced in the project file (TestApp.csproj). Any comments on that would also be appreciated.]
MonoTouch uses a superset of the Silverlight framework, not 3.5, and there are currently no xbuild targets for MonoTouch and its framework version. Implementing this will require custom targets that override framework assembly resolution, like the Silverlight and MonoDroid targets.
For now, I suggest you use the build command of MonoDevelop's commandline tool, mdtool, i.e.
/Applications/MonoDevelop.app/Contents/MacOS/mdtool build
I'm having an issue with the Attrib task from the MSBuild Community Tasks Project when running on a 64 bit build machine.
I've put together this small test project to show what the problem is:
<Project ToolsVersion="3.5" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath32)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="PrintProperties">
<Message Text="MSBuildCommunityTasksPath: $(MSBuildCommunityTasksPath)"/>
<Message Text="MSBuildCommunityTasksLib: $(MSBuildCommunityTasksLib)"/>
<Message Text="MSBuildNodeCount: $(MSBuildNodeCount)"/>
<Message Text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)"/>
<Message Text="MSBuildExtensionsPath32: $(MSBuildExtensionsPath32)"/>
<Message Text="MSBuildProjectDirectoryNoRoot: $(MSBuildProjectDirectoryNoRoot)"/>
<Message Text="MSBuildToolsPath: $(MSBuildToolsPath)"/>
<Message Text="MSBuildToolsVersion: $(MSBuildToolsVersion)"/>
<Message Text="MSBuildBinPath: $(MSBuildBinPath)"/>
<Message Text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)"/>
<Message Text="MSBuildProjectDefaultTargets: $(MSBuildProjectDefaultTargets)"/>
<Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)"/>
<Message Text="MSBuildProjectExtension: $(MSBuildProjectExtension)"/>
<Message Text="MSBuildProjectFile: $(MSBuildProjectFile)"/>
<Message Text="MSBuildProjectFullPath: $(MSBuildProjectFullPath)"/>
<Message Text="MSBuildProjectName: $(MSBuildProjectName)"/>
<Message Text="MSBuildStartupDirectory: $(MSBuildStartupDirectory)"/>
</Target>
<Target Name="TestAttrib" DependsOnTargets="PrintProperties">
<Attrib Files="Test.txt" ReadOnly="false" />
</Target>
</Project>
when I attempt to build this project with MSBuild using TestAttrib as the Target I get the following results
C:>msbuild "C:_Source Code\Test.vbproj" /t:TestAttrib
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.4016]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 7/09/2009 2:50:12 PM.
Project "C:_Source Code\Test.vbproj" on node 0 (TestAttrib target(s)).
MSBuildCommunityTasksLib: C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBu
ild.Community.Tasks.dll
MSBuildNodeCount: 1
MSBuildExtensionsPath: C:\Program Files\MSBuild
MSBuildExtensionsPath32: C:\Program Files (x86)\MSBuild
MSBuildProjectDirectoryNoRoot: _Source Code
MSBuildToolsPath: c:\Windows\Microsoft.NET\Framework64\v3.5
MSBuildToolsVersion: 3.5
MSBuildBinPath: c:\Windows\Microsoft.NET\Framework64\v3.5
MSBuildExtensionsPath: C:\Program Files\MSBuild
MSBuildProjectDefaultTargets: Build
MSBuildProjectDirectory: C:_Source Code
MSBuildProjectExtension: .vbproj
MSBuildProjectFile: Test.vbproj
MSBuildProjectFullPath: C:_Source Code\Test.vbproj
MSBuildProjectName: Test
MSBuildStartupDirectory: C:\
C:_Source Code\Test.vbproj(26,5): error MSB4062: The "MSBuild.Community.Tasks.Attrib" task could not be loaded from the assembly C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll. Could not load file or assembly 'file:///C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, and that the assembly and all its dependencies are available.
Done Building Project "C:_Source Code\Test.vbproj" (TestAttrib target(s)) -- FAILED.
Build FAILED.
"C:_Source Code\Test.vbproj" (TestAttrib target) (1) ->(TestAttrib target) -> C:_Source Code\Test.vbproj(26,5): error MSB4062: The "MSBuild.Community.Tasks.Attrib" task could not be loaded from the assembly C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll. Could not load file or assembly 'file:///C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, and that the assembly and all its dependencies are available.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.05
Why is the MSBuild searching for the Attrib task in C:\Program Files\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.dll when I've explicitly imported the tasks using the (MSBuildExtensionsPath32) variable?
I seem to have fixed the issue by editing line 6 of "C:\Program Files (x86)\MSBuild\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"
Originally it was:
<MSBuildCommunityTasksPath Condition="'$(MSBuildCommunityTasksPath)' == ''">$(MSBuildExtensionsPath)\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
and I altered it to:
<MSBuildCommunityTasksPath Condition="'$(MSBuildCommunityTasksPath)' == ''">$(MSBuildExtensionsPath32)\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
note the change of $(MSBuildExtensionsPath) to $(MSBuildExtensionsPath32)
While this seems to have sorted out my issue for now, I'm not sure why I had to edit the MSBuild.Community.Tasks.Targets file in the first place - I assumed the installer would have made sure the file was correct. So perhaps editing the MSBuild.Community.Tasks.Targets file isn't the best idea in the world, so be careful if you decide to follow my lead.
This is obviously far too late an answer, but I thought I would add to this in case anyone else is having this problem. Instead of editing the MSBuild.Community.Tasks.Targets file, you can just define the MSBuildCommunityTasksPath property in a property group in your build file. For example, I have something like this at the top of my build script:
<PropertyGroup>
<ToolsDirectory>$(MSBuildProjectDirectory)\tools</ToolsDirectory>
<MSBuildCommunityTasksPath>$(ToolsDirectory)\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
</PropertyGroup>
I then store the MSBuildCommunityTasks folder in a tools directory in source control. It means that other folk can pull out the source and build it straight away without installing anything.
Cheers,
Adam
This is very out of date help. The ms build process has changed since this ticket, best to follow the instructions here https://github.com/loresoft/msbuildtasks
For my project, I used a Build folder in my solution and in the solution I create a MSBuildTasks Folder where I copy the latests MBBuild.Community.Task files in the Zip file release. and put the following lines in my msbuild file
<PropertyGroup>
<MSBuildCommunityTasksPath>.\MSBuildTasks</MSBuildCommunityTasksPath>
</PropertyGroup>
<Import Project=".\MSBuildTasks\MSBuild.Community.Tasks.Targets" />