More on “Continuous Integration in .NET”
November 11, 2011 on 2:46 pm | In Continuous Integration, DotNet | No CommentsI’ve recently got the sales report from Manning about my book “Continuous Integration in .NET”. I’m very happy to report it sells quite well!
And speaking about the book. My friend Mateusz Łoskot send me an excerpt from the ACCU discussion board discussing my book. Here it is:
> Interesting you mention the Manning books on Dependency Injection and Continuous Integration… is there really a whole books-worth of stuff in each of those topics??
If you are in the .NET world then then ‘Continuous Integration in
.NET’ is really worth the time invested. It covers most of commonly
used tools (CC.NET, MSBuild & Team System, TeamCity). Goes over
integration of unit testing, code metrics, analyse tools, source
control and these like (if I recall correctly there is a section on
building installation package and getting you DB related changes under
CI as well).
However, it lack some obscure topics (e.g. I would really like to
facilitate Hudson, Maven and Sonar, but I don’t even recall a word on
these also NAnt isn’t presented too well).
Even thought, if you are just starting with CI I would give it a go.
You could skip it if you already have some CI in house and just need
to improve / extend what it offers. It’s alway nice to have a look
around, but I find hands-on experience much more important in this
area.
Visual Studio 2010 Professional and Hudson / Jenkins CI and FxCop
June 15, 2011 on 9:03 am | In Continuous Integration, DotNet, MSBuild | No Comments
Visual Studio 2010 Premium and Ultimate do have the code analysis feature build in. What this feature does is static code analysis of your source code (or IL to be specific). Unfortunately the Professional edition lacks the build in integration (no Analysis tab in the project properties). Here is a way to easily integrate Visual Studio 2010 Professional with FxCop. FxCop is a standalone Code Analysis version that comes together with “Microsoft Windows SDK for Windows 7 and .NET Framework 4 Version 7.1”. Actually if you download and install the SDK you will get the FxCop installer in %ProgramFiles%\Microsoft SDKs\Windows\v7.1\Bin\FXCop. You will have to install it from there (yeah installer in a installer
.
Here is how to built it into Visual Studio 2010 and into continuous integration process. First of all, I like to have all the assets in my repository. So I went and copied all the FxCop files into the tools/FxCop directory into the repository. I didn’t wanted to use the FxCop project files (they add unnecessary friction with editing the file – sometimes on runtime). I decided to go the command line way all the way. The easiest solution is to define all the rules you want to obey in the ruleset file. Ruleset file is a XML file that looks like this:
1: <?xml version="1.0" encoding="utf-8"?>
2: <RuleSet Name="Codefusion Rules" Description="This is the Codefusion rule set." ToolsVersion="10.0">
3: <Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
4: <Name Resource="ExtendedDesignGuidelineRules_Name" />
5: <Description Resource="ExtendedDesignGuidelineRules_Description" />
6: </Localization>
7: <IncludeAll Action="Error" />
8: <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
9: <Rule Id="CA1000" Action="Warining" />
10: </Rules>
11: </RuleSet>
The example above states that all the rules (IncludeAll) are threated as errors with one exception being a Warning (<Rule Id=…). You can define the rules as you wish. Fortunately Visual Studio 2010 Professional has the build in editor for the ruleset files. Using this editor you can easily choose the rules to obey (or not).
When you are done with the ruleset place it somewhere in your repository and define post build event like this one:
The text for the post build event is:
if $(ConfigurationName) == Release $(SolutionDir)Codefusion.Common\Tools\FxCop\FxCopCmd.exe /file:$(SolutionDir)S000.Basic\bin\$(ConfigurationName)\Codefusion.S000.Basic.dll /ruleset:=$(SolutionDir)Codefusion.Common\FxCopRules\CodefusionRules.ruleset /rulesetdirectory:$(SolutionDir)Codefusion.Common\Tools\FxCop\Rules /console
This way if you compile the project in Release mode you will get all the rules defined in ruleset file checked. You will see the violations in the Error List area. You can still jump to the line where violation occurs by double-clicking the line with report.
You can always suppress the messages for the rules you chosen to obey if in this particular case they don’t make sense. You can do it globally in the GlobalSuppressions.cs file. Like that:
1: [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Codefusion")]
Or directly in the code like that:
1: [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1820:TestForEmptyStringsUsingStringLength")]
2: public static string MakeMD5Hash(this string value)
3: {
4: if (value == null)
5: {
6: throw new ArgumentNullException("value");
7: }
8: else if (value == string.Empty)
9: {
10: throw new ArgumentException(Resources.BasicStrings.ErrorMsgValueCannotBeEmpty + ".", "value");
11: }
12:
13: ...
To make the suppressions work (suppressions are inline or global exceptions from the ruleset) you will have to define the compiler directive like that:
It will define a constant in the project file:
<DefineConstants>CODE_ANALYSIS</DefineConstants>
If you are using the continuous integration technique you can put the command similar to the one in post build event into the build project. In MSBuild it will look like this:
1: <Target Name="Analysis" >
2: <Exec Command="$(MSBuildProjectDirectory)\Codefusion.Common\Tools\FxCop\FxCopCmd.exe /file:S000.Basic\bin\$(Configuration)\Codefusion.S000.Basic.dll /ruleset:=Codefusion.Common\FxCopRules\CodefusionRules.ruleset /rulesetdirectory:Codefusion.Common\Tools\FxCop\Rules /out:FxCopReport.xml /forceoutput" ContinueOnError="false" />
3: </Target>
This way you will get get the XML file with the violations report that your CI server can interpret and thanks to the ContinueOnError=”false” attribute you will get the broken build if any of the violations will be found.
In Hudson/Jenkins you can use the Violations plug-in (you will have to install it) to show the violations in the build report. To do so you need to to configure the project like this:
Happy coding!
Continuous Integration in .NET – dead tree edition
March 13, 2011 on 9:12 pm | In Continuous Integration, DotNet | No Comments
Finally it happened. I’ve just got my author copies of “Continuous Integration in .NET” the book I coauthored. I’m very, very happy because it was a long journey and finally it happened. My first book is out. I would like to thank all the people who helped at Manning and outside. I was considering writing a longer post about the process, the ups and the downs, but I decided not to. I might return to that thought later. In a mean time if you are considering coauthoring a book with someone you don’t know think twice. If you are considering writing something together with Craig Berntson and want to know my honest opinion write to me. Hoppe you will consider this book interesting.
Hudson Continuous Integration LED message board monitor
January 2, 2011 on 8:59 pm | In Continuous Integration, DotNet | 2 CommentsKnowing the state of the build is one of the most important aspects of Continuous Integration. Team should get the information about the problems with he build as soon as possible. If the quality of source code degrades rendering the build to fail team, should jump in and fix the problem.
The most popular group of tools that make the swift reaction possible are the tray notifiers. Small programs that reside somewhere in the corner of the screen and show one of the 3 states the build server is ever in:
1. Building
2. Failed
3. Yet another successful build!
Oh, and well… not working (if the CI server is down). Some teams use emails or even SMS to inform about the broken build. Fore some it is not enough. The history of “alternative feedback mechanism” is long. It includes inventions like:
- Traffic Lights (to tell you the truth it is my favourite!)
I didn’t wanted to be worse. I wanted my won gadget. My budget was limited so I’ve picked something cheap but funny. What can be cheaper than USB toy, I thought. But finding a device that can be customized/programmed was not so easy. Most of the USB toys are dummy devices that take the 5V from the USB socket to simply power something up. But after a small research I’ve stumbled upon something interesting: LED Message Board from Dream Cheeky. I’ve asked the manufacturer about the possibility to program the device and received short but complete instruction how to use it programmatically.
The LED Message Board is a HID device. HID stays for Human Interface Device – a device that can interact with humans. In my case it was the device input that should interact with my developers and show them that something is wrong on the CI server. So I’ve looked for a HID library on the net and found a nice piece of work from Mike Obrien. A .NET Framework library ready to use with any HID device. Neat!
We are using Hudson CI at CODEFUSION (my company). It has a nice XML API (next to JSON and Python API) that anyone can use of. So I had everything I needed to start coding (for fun)!
Getting Hudson CI build state
As I mentioned earlier Hudson CI exposes quite robust XML API that you can consume over HTTP as you like. To get the basic information about all available APIs substitute your Hudson URL with API like this:
To the the the basic XML API document write api/xml:
http://yourserver/hudson/api/xml
This document holds only the subset of information’s that Hudson CI can deliver. The fist level does not contain what I needed – the information if any of the jobs defined is in broken state. Trying another depths /api/xml?depth=1I found the last buildResult in jobs that was what I needed! You can filter the returned XML using the tree parameter like this:
http://yourserver/hudson/api/xml?tree=jobs[name,lastBuild[result]]
In return I’ve got nicely formatted XML with all the data I’ve needed
<hudson>
<job>
<name>S000.Framework</name>
<lastBuild>
<result>SUCCESS</result>
</lastBuild>
</job>
<job>
<name>S001.Cfms</name>
<lastBuild>
<result>SUCCESS</result>
</lastBuild>
</job>
</hudson>
All I needed now is to get the file and parse it. One more thing I had to do before it was possible. My Hudson CI server uses the Active Directory authentication. There is access without an AD account and a proper values in Hudson security matrix. After some investigation on the HTTP communication the browser is normally performing with the server (I used Firebug – excellent Firefox plug-in for web developers) I’ve came with following code:
1: // Non blocking lock
2: if (Monitor.TryEnter(_TimerLocker))
3: {
4: // Create web client instance
5: MyWebClient WebClient = null;
6:
7: try
8: {
9: WebClient = new MyWebClient();
10:
11: // Log-in in if neccessary
12: if (_UserName != null && _Password != null)
13: {
14: // Readc login page and dump result to dummy string
15: string Dump = (new StreamReader(WebClient.OpenRead(_Uri.ToString() + "loginEntry"))).ReadToEnd();
16:
17: System.Collections.Specialized.NameValueCollection Variables = new System.Collections.Specialized.NameValueCollection();
18: Variables.Add("j_username", _UserName);
19: Variables.Add("j_password", _Password);
20: Variables.Add("from", "/");
21: Variables.Add("Submit", "log in");
22:
23: WebClient.UploadValues(_Uri.ToString() + "j_acegi_security_check", "POST", Variables);
24: }
25:
26: StreamReader RequestReader = new StreamReader(WebClient.OpenRead(_Uri.ToString() + _HudsonFiler));
27: string ResponseFromServer = RequestReader.ReadToEnd();
28:
29: XElement XElement = XElement.Parse(ResponseFromServer);
30:
31: foreach (XElement Element in XElement.Elements())
32: {
33: // TODO mk from mk; meybe add project filtering
34: //Element.Element("name");
35: XElement LastBuildElement = Element.Element("lastBuild");
36:
37: if (LastBuildElement != null)
38: {
39: XElement IsSuccessResult = LastBuildElement.Element("result");
40:
41: if (IsSuccessResult != null && IsSuccessResult.Value.Equals("FAILURE"))
42: {
43: _IsOk = false;
44: break;
45: }
46: }
47:
48: _IsOk = true;
49: }
50: }
51: catch (Exception ex)
52: {
53: _LogProvider.Error(ex);
54: }
55: finally
56: {
57: WebClient.Dispose();
58:
59: // Exit from critical section
60: Monitor.Exit(_TimerLocker);
61: }
62: }
63: return _IsOk;
First, since I’m going to write a Windows Serve that periodically check Hudson CI I’m making a non blocking lock on the code I will run in a loop. If something hangs inside (like the HTTP request) the application will not run in a deadly loop that can eventually eat up all the resources. I’m using a overloaded WebClient class to perform all the operations. The overload was necessary because I have a secured Hudson CI server and the login is a little tricky in such case. Here is the code for the overloaded WebClient with cookie and changed timeout.
1: namespace HudsonLedSygnalizer
2: {
3: #region Using
4: using System;
5: using System.Net;
6: #endregion
7: internal class MyWebClient : WebClient
8: {
9: #region Private variables
10: private CookieContainer m_container = new CookieContainer();
11: #endregion
12:
13: #region Overrides
14: protected override WebRequest GetWebRequest(Uri address)
15: {
16: WebRequest request = base.GetWebRequest(address);
17: if (request is HttpWebRequest)
18: {
19: (request as HttpWebRequest).CookieContainer = m_container;
20: (request as HttpWebRequest).Timeout = 6000;
21: }
22: return request;
23: }
24: #endregion
25: }
26: }
What we are about to do with it is essentially log-in like we were to log-on to the site over normal web browser. Maintaining the session by providing session cookie to the server.
The login URL is:
http://yourserver/hudson/loginEntry
You will have to read this URL to get the response cookie that needs to be maintained. The actual return is of no use to use. We are interested only in cookies. Having the cookie we can log-in. To do so you will have to send POST request to the server containing:
- j_username – set to the Hudson account name
- j_password – set to the password for the Hudson account name
- from – set to “\”
- Submit set to “log in”
If you are using AD authentication the request needs to go to:
http://yourserver/hudson/j_acegi_security_check
I was using WebClient.UploadValues to get the POST request rolling.
From now on you should be authenticated and ready to get the information about last builds from Hudson CI. To do it you will have to use the API provided by the CI server that I described earlier in this post. I was only interested if any of the build is broken. So I searched in a job for a result that contained FAILURE text. If found I knew that the CI server as a whole is in broken state and consequently it was the time to lighten up the alarm signal on the LED Message Board.
Programming LED Message Board
Every HID device has a vendor and product ID. The two numbers are unique and you need them to contact the device. The ones for LED Message Board are
private int _VentodId = 0x1d34; private int _ProductId = 0x0013;
Getting the device is easy with the Mike Obrien HID library I mentioned earlier:
1: private void MyDetectMessageBoard()
2: {
3: HidDevice[] HidDeviceList;
4:
5: try
6: {
7:
8: HidDeviceList = HidDevices.Enumerate(_VentodId, _ProductId);
9:
10: if (HidDeviceList.Length > 0)
11: {
12: _MessageBoard = HidDeviceList[0];
13:
14: _MessageBoard.Open();
15: }
16: }
17: catch (Exception ex)
18: {
19: _LogProvider.Error(ex);
20: }
21: }
What I wanted to do is to simply display a “big red blinking eye” that watches my team if something is not working well on the CI server. To display the “big red eye” you will have to send following data to the device:
1: byte[] Packet0 = new byte[] { 0x00, 0x00, 0x00, 0xFF, 0xFC, 0x7F, 0xFF, 0xF8, 0x3F };
2: byte[] Packet1 = new byte[] { 0x00, 0x00, 0x02, 0xFF, 0xF0, 0x1F, 0xFF, 0xE0, 0x0F };
3: byte[] Packet2 = new byte[] { 0x00, 0x00, 0x04, 0xFF, 0xF0, 0x1F, 0xFF, 0xF8, 0x3F };
4: byte[] Packet3 = new byte[] { 0x00, 0x00, 0x06, 0xFF, 0xFC, 0x7F, 0xFF, 0xFF, 0xFF };
I wrote a quick Excel sheet to calculate the hex values needed for a given display pattern.
To display the signal you have to do the following:
1: private void Timer_Elapsed(object sender, ElapsedEventArgs e)
2: {
3: // Try to detect message board
4: if (_MessageBoard == null)
5: {
6: MyDetectMessageBoard();
7: }
8:
9: // Try to send the signal
10: if (_MessageBoard != null)
11: {
12: _MessageBoard.Write(Packet0);
13: _MessageBoard.Write(Packet1);
14: _MessageBoard.Write(Packet2);
15: _MessageBoard.Write(Packet3);
16: }
17: }
As you can see the I’m using the Timer to display the “big red eye”. It is because the diodes are fleshing for a fraction of a second and you have to keep up refreshing them to get continuous display. I used System.Timers.Timer class to do the work. I set the interval so that the LED will flash – for a better effect.
1: internal LedNotifier()
2: {
3: // Init timer
4: _Timer = new Timer();
5: _Timer.Enabled = false;
6: _Timer.Interval = 1000;
7: _Timer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
8:
9: // Init message board
10: MyDetectMessageBoard();
11:
12: }
We almost have all the ingredients. The last thing is a windows service. It will be very simple service that incorporates a new timer to perform periodical checks on the Hudson CI server and if necessary turning on the LEDs. I’m not providing the source code here but you can download it here:
DOWNLOAD Hudson CI LED Notifier Please write me an email to get the source code.
That’s it hope you can find any use for the information provided in that post. Here last but not least the device in motion!
Speaking about continuous integration
January 16, 2010 on 7:09 pm | In Continuous Integration | No Comments
I will be speaking on Wednesday (20.01.2010) in Krakow, Poland at the Karkow .NET Developers Group meeting. The session is about Continuous Integration in .NET. So if you like hear what I have to say about CI meet me at ABB ISDC, Pałac Pugetow, ul. Starowislna 13, Krakow at 18:30. I believe the attendance is free but registration is required. See you in Krakow!
Selenium RC and FitNesse as a service on Windows Server 2008
November 7, 2009 on 10:19 pm | In Continuous Integration, Windows | 2 CommentsIf you are working in a team or running a continuous integration process the most comfortable way to run tools like Selenum RC Server or FitNesse is to install them as a windows service. I was doing this earlier on my old Windows Server 2003 by issuing the instsrv.exe (to install a service) on srvany.exe (to run anything) – both from Windows Resource Kit. I had to edit the registry to provide what exactly do I wanted to run (java –jar selenium-server.jar or java –jar fitnesse.jar).
But there is no Windows Resource Kit for 2008. You might use the sc.exe and get the old srvany.exe (with compatibility issues according to Microsoft itself). It would work but why bother when there is a Non-Sucking Service Manager! All you have to do to install a service with this tool is to download it, issue a
nssm.exe install SeleniumRC
and edit this dialog box:
Click Install service and you are done. Selenium RC Server is installed. All you have to do is to start it. Voila!
How to make CruiseControl.NET accept SSL certificate under Windows Server 2008?
October 24, 2009 on 11:44 pm | In Continuous Integration, Windows | 1 CommentIf you are running CruiseControl.NET under the Local System account and your SVN server certificate was issued by yourself (or by VisualSVN Server) you will quickly run into trouble. Normally if you run any command on your repository you will get this information:
C:\Program Files\svn\bin>svn log https://your_server/svn/your_repository/trunk –username username –password password
Error validating server certificate for ‘https://your_server:443′:
- The certificate is not issued by a trusted authority. Use the
fingerprint to validate the certificate manually!
- The certificate hostname does not match.
Certificate information:
- Hostname: your_server
- Valid: from Sat, 26 Sep 2009 17:24:27 GMT until Tue, 24 Sep 2019 17:24:27 GMT
- Issuer: your_server
- Fingerprint: 24:8e:f6:ba:c7:a6:3f:69:32:c0:21:92:64:44:62:fe:2c:bb:b4:69
(R)eject, accept (t)emporarily or accept (p)ermanently?
If you accept you will not be bothered again. But CCNet works as a Windows Service. There is no one to make the decision. How to deal with this issue. Well earlier it was easy enough. You had to use one of the security holes and start cmd.exe in interactive mode wit at command (look here for more details). But with Windows Server 2008 it is not possible you will simply get this:
C:\Users\Administrator>time
The current time is: 23:31:11.59
Enter the new time:
C:\Users\Administrator>at 22:32 /interactive cmd.exe
Warning: Due to security enhancements, this task will run at the time
expected but not interactively.
Use schtasks.exe utility if interactive task is required (‘schtasks /?’
for details).
Added a new job with job ID = 1
How to deal with this. There is very easy solution. Set the CruiseContril.NET service “Allow to interact with desktop” flag (Start –> Control Panel –> Administrative Tools –> Services –CruiseControl.NET) like this
Restart the service and wait a while for this windows to appear:
Select show me the message.
Voila! You have command line as Local System user available. You can now issue the
C:\Program Files\svn\bin>svn log https://your_server/svn/your_repository/trunk –username username –password password
command and accept the SSL certificate permanently.

From this time on you CCNet server will not have any problems with accessing your secured repository.
Buy Continuous Integration in .NET book
October 19, 2009 on 7:52 am | In Books, Continuous Integration | 2 CommentsThe Continuous Integration in .NET book is available as an early access edition from MEAP. For those of you that are not familiar with MEAP it stands for Manning Early Access Program and it is the place where you can download a free chapter and buy the whole book printed or as an ebook before it gets published. You will get continuously chapter after chapter successively as they will be written.
Next big thing – continuous integration book
August 14, 2009 on 9:39 pm | In Books, Continuous Integration | 3 Comments
I’m going to write a book about Continuous Integration in .NET for the Manning Publications. I’m sure I don’t have to tell you how exited am I. I will join the noble team of Manning authors like John Skeet, Ayende Rahien or Roy Osherove. I’ll keep you posted about the progress. In the mean time let me give you some history.
I’ve once written an article for Software Developers Journal about Continuous Integration in .NET. It was very well received. I always thought I have a lot more to say in this topic. The idea to write a book came while speaking with my good friend hsd (well I have more and more to thank you for
. I’ve tried to propose the book to a polish publisher Helion. Very fortunately for me they said there is not enough place on the polish marketplace to get enough sell (I’ve blogged about this in polish). I presume they know better. I’ve already buried the idea about the book when I saw the ASP.NET MVC 1.0 Quickly book from Packt Publication. It was written by a guy from Belgium (Maarten Balliauw). I’ve read his blog and I realized has not native English speaker. “If he can, why not to try myself?” I thought and written a short proposal for Packt. They were interested! I’ve worked on the proposal with the Acquisition Editor and I’ve shortly after that I’ve got the information that the book was “committed”. I was very, very happy until something went wrong at Packt (the went scared by a download stats of one of the tools I wanted to write about). The book was “uncommitted” and we didn’t sign the agreement. I don’t throw my hands up! I thought if they are interested probably someone else will be too. I’ve send view more proposals to other publishers and the Manning appeared. In the mean time Packt turned to be after all interested in me writing the book. The Acquisition Editor at Packt Publishing was a great guy. I’m sure it would be great to write a book for them but it was to late. Manning found me a co-writer Craig Berntson. Someone that speaks English a lot better than I and has a know how in continuous integration. The way the Manning deals with his authors seems very provisional and I’ve very glad to get this opportunity.
So be aware. The best Continuous Integration in .NET book comes sooner than you expected!
Writing MSBuild Custom Task
March 13, 2008 on 8:16 pm | In Continuous Integration, MSBuild | 9 CommentsScenario: we have Subversion server to manage our source code and a build server (CruiseControl.NET) to manage our deployment. We have decided to automatically set the SVN revision number to our assembly version.
[assembly: System.Reflection.AssemblyVersion("1.2.3.0")] [assembly: System.Reflection.AssemblyFileVersion("1.2.3.0")]
So we will replace the last 0 with the current Subversion revision number. How to do this? One way to achieve this is to modify the AssemblyInfo.cs and read the modified number from that exists. The file modification is easy with MSBuild Community Task FileUpdate
<FileUpdate Files="Cic.P001001PropertiesAssemblyInfo.cs" Regex="(d+).(d+).(d+).(d+)" ReplacementText="$1.$2.$3.$(RevisionNumber)" />
But how to read it back? Well there is no easy way. I have written a custom MSBuidl task to achieve this like this:
<AssemblyInfoReader Path="PropertiesAssemblyInfo.cs" Property="AssemblyVersion"> <Output TaskParameter="Value" ItemName="ApplicationVersion" /> </AssemblyInfoReader>
Writing a custom MSBuild task is fairly easy. You have to Reference Microsoft.Build.Framework and Microsoft.Build.Utilities and implement Microsoft.Build.Framework.ITask. Just like this:
namespace Cic.MsBuildTasks { public class AssemblyInfoReader : Microsoft.Build.Framework.ITask { #region Private Varaibels private string path; private string property; private string value; #endregion #region Fields [Microsoft.Build.Framework.Required] public string Path { get { return path; } set { path = value; } } [Microsoft.Build.Framework.Required] public string Property { get { return property; } set { property = value; } } [Microsoft.Build.Framework.Output] public string Value { get { return this.value; } set { this.value = value; } } #endregion #region ITask Members private Microsoft.Build.Framework.IBuildEngine engine; Microsoft.Build.Framework.IBuildEngine Microsoft.Build.Framework.ITask.BuildEngine { get { return engine; } set { engine = value; } } bool Microsoft.Build.Framework.ITask.Execute() { string message; value = string.Empty; try { value = MyReadAssemblyInfoProperty(); message = string.Format( "AssemblyInfo property {0} read. Property value {1}", property, value); } catch (System.Exception e) { message = string.Format( "Error reading AssemblyInfo property {0}. Error: {1}", property, e.Message); } Microsoft.Build.Framework.BuildMessageEventArgs args = new Microsoft.Build.Framework.BuildMessageEventArgs( message, string.Empty, "AssemblyInfoReaderTask", Microsoft.Build.Framework.MessageImportance.Normal); engine.LogMessageEvent(args); return true; } private Microsoft.Build.Framework.ITaskHost host; Microsoft.Build.Framework.ITaskHost Microsoft.Build.Framework.ITask.HostObject { get { return host; } set { host = value; } } #endregion #region Internals private string MyReadAssemblyInfoProperty() { string propertyValue; // Eraly return if (!System.IO.File.Exists(path)) return ""; foreach (string line in System.IO.File.ReadAllLines(path)) { if (line.Contains(property)) { try { propertyValue = line.Remove(0, line.IndexOf('"') + 1); propertyValue = propertyValue.Remove( propertyValue.LastIndexOf('"'), propertyValue.Length - propertyValue.LastIndexOf('"')); // return matching property value return propertyValue; } catch { // Ignore errors } } } return string.Empty; } #endregion } }
Powered by WordPress with Pool theme design by Borja Fernandez.
Text © Marcin Kawalerowicz. Hosting CODEFUSION.


