[p4] Adding Changelist # of project to .Net Assembly?
Pavloff, Alex (IE) @ SONOMAEO
alex.pavloff at l-3com.com
Fri Oct 20 13:56:55 PDT 2006
Well, I've got a solution. It's not pretty, but it also doesn't require
any 3rd party build systems to be installed.
Add these commands to the "pre-build event command line" for a C#
project.
---
REM Determine the current client
IF DEFINED P4CLIENT SET CURRENTCLIENT=%P4CLIENT%
IF NOT DEFINED P4CLIENT SET CURRENTCLIENT=%COMPUTERNAME%
REM Set the file that we're outputting too
SET CHANGELISTFILE=$(ProjectDir)Properties\ChangeListNumber.cs
REM Set the command we use to get the current changelist
SET P4CHANGECMD=p4 changes -m1 $(ProjectDir)...@%CURRENTCLIENT%
REM Hack out the changelist #
FOR /F "tokens=2" %%A IN ('%P4CHANGECMD%') DO SET VALUE=Changelist %%A
REM Set the beginning and end of the line we're going to add
SET FRONT=[assembly: AssemblyCopyright("
SET END=")]
REM Put together the file
> %CHANGELISTFILE% echo using System.Reflection;
>> %CHANGELISTFILE% echo using System.Runtime.CompilerServices;
>> %CHANGELISTFILE% echo using System.Runtime.InteropServices;
>> %CHANGELISTFILE% echo %FRONT% %VALUE% %END%
---
Create a file named ChangeListNumber.cs in the Properties folder of a
project, Add it to the project, but Exclude it from source control (as
it it will be regenerated with each build).
Remove the "AssemblyCopyright" attribute from the stock AssemblyInfo.cs,
else you'll get a duplicate attribute compile error.
Now, on build, this file ChangeListNumber.cs will be created, and will
be included into the project. I'm currently using the AssemblyCopyright
attribute, as it's a plain string and is easily viewable by just right
clicking on an assembly and getting the properties. The version
attributes want the w.x.y.z syntax.
It works, but I do feel like I'm tricking Visual Studio. Oh well. NT
batch language is just bizarro -- this is my first real attempt to do
anything with it. Most scripting languages will let you put the output
of a command into a variable with a few single quotes -- that FOR loop
up appears to be the only way to do it. Also, there's absolutely no way
to each something to a file without appending a line-end.
-Alex
-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of Jeff Grills
Sent: Thursday, October 19, 2006 10:19 PM
To: 'Nau, Michael'; Pavloff, Alex (IE) @ SONOMAEO
Cc: perforce-user at perforce.com
Subject: Re: [p4] Adding Changelist # of project to .Net Assembly?
I worked on a project which embedding our build information in a module
that
was compiled, but that had the negative side effect of itself causing a
build to be necessary. At that time we were using the head changelist
number for versioning, but maybe if we had used "p4 changes -m 1 //path"
to
get the head changelist number as you do, we could have made sure to
update
the file only when it was out of date, which would have prevented an
otherwise unnecessary build.
Instead, we used a product called Resource Tuner Console
(http://www.heaventools.com/command-line_resource_editor.htm), and if
the
executable been changed by the build process, we'd invoke this tool on
our
executable to brand it with the build information. It was really
useful,
and I'd recommend the tool to others. I have no affiliation with the
company other than having had been a satisfied customer. This may be a
good
fallback if you can't find a way to update the version in another
manner.
j
-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of Nau, Michael
Sent: Thursday, October 19, 2006 11:35 PM
To: Pavloff, Alex (IE) @ SONOMAEO
Cc: perforce-user at perforce.com
Subject: Re: [p4] Adding Changelist # of project to .Net Assembly?
I started down that same path a few years ago, and discovered no part of
a
AssemblyVersion can be larger than 65534. So we ended up stuffing the
changelist number into the AssemblyDescription attribute.
With regards to how we pull the info, we wrap our build with an nant
script
that takes care of calling perforce to figure out the latest changelist
then
dynamically updating our AssemblyInfo.cs files at build time.
-Mike
-----Original Message-----
From: perforce-user-bounces at perforce.com
[mailto:perforce-user-bounces at perforce.com] On Behalf Of Pavloff, Alex
(IE) @ SONOMAEO
Sent: Thursday, October 19, 2006 6:04 PM
To: perforce-user at perforce.com
Subject: [p4] Adding Changelist # of project to .Net Assembly?
Hi perforce-user,
For our C/C++ project We've added a "p4 changes -m1 $...@$(P4CLIENT)"
step
to our makefiles -- and taken the output from that and generated a .c
file
from this. This file contains the highest changelist # at the time of
build
of the source in the directory.
As long as this was built from checked-in source, it can be used by
testers
and what not as a "what I'm testing" #. If you need to rebuild that
particular rev, sync to the changelist #, rebuild, wa-lah.
Now, I'm thinking about trying to do the same thing with a Visual Studio
2005/C# project -- and I believe that the "correct" way to do this would
be
to generate generate the AssemblyVersion attribute from the Perforce
changelist #, such that it'd be
[assembly: AssemblyVersion("1.0.0.98776")]
Where 98776 is the Changelist #. Normally this attribute is hardcoded
in
the AssemblyInfo.cs file.
Does anyone have any ideas about how to generate this in the Pre-Build
steps
for C#/.Net applications?
Thanks!
-Alex
_______________________________________________
perforce-user mailing list - perforce-user at perforce.com
http://maillist.perforce.com/mailman/listinfo/perforce-user
More information about the perforce-user
mailing list