ant store variable in scriptdef or call task in script def - variables

My knowledge of ant is close to nothing.
i do understand it should not be used as a programming language but i'm a consumer of a certain ant project and want to modify something in my own project while using the libraries that project offers me.
the main point i want to do is I have a string and need to modify it before sending it to the parent project target.
i'll try providing a code easy to understand, but at the moment the part i have left is:
either store the value in a variable instead of a property (not sure how to do this)
directly call the other target from my javascript function.
so this is the code:
<target name="deploy-custom" depends="init">
<scriptdef name="replaceString" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
echo.setMessage("replace " + fileOut );
echo.perform( );
project.setProperty("undeploy_name", fileOut);]]>
</scriptdef>
<echo message="executing target deploy-custom" />
<for param="file">
<path>
<fileset dir="${mydir}/content/custom-deploy">
<include name="*.war" />
</fileset>
</path>
<sequential>
<replaceString fileIn="#{file}" directoryFile="${mydir}/content/custom-deploy/" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="${undeploy_name}" />
</JBossCLI>
<deployToLiferay file="#{file}" />
</sequential>
</for>
<echo>ABRS custom banklets deployed!</echo>
</target>
so my question is at the time i try to save the undeploy_name property can I just call the target deployToLiferay? if not is there a way i can save that in a variable instead a property?
i don't mind using other language instead of javascript but not really sure how can i do what i need to do.
based on the info i found in here i'm now trying to focus on the using the script directly. this is the info i get:
https://coderanch.com/t/108191/call-ant-macrodef-groovy-script
i tried to modify my script to something like this:
<macrodef name="undeploy">
<attribute name="undplPattern" />
<sequential>
<echo message="undeploy undplPattern #{undplPattern}" />
<JBossCLI port="${jboss.port.management-native}">
<undeploy namePattern="#{undplPattern}" />
</JBossCLI>
</sequential>
</macrodef>
<scriptdef name="undeploy-pattern" language="javascript">
<attribute name="fileIn" />
<attribute name="directoryFile" />
<![CDATA[
var echo = project.createTask("echo");
var fileName = attributes.get("filein"); //get attribute for scriptdef
var directoryIn = attributes.get("directoryfile"); //get attribute for scriptdef
echo.setMessage("file name: " + fileName );
echo.perform( );
echo.setMessage("dir in " + directoryIn );
echo.perform( );
var fileOut = fileName.replace(directoryIn, "");
fileOut = fileOut.replace(/\d+/g, "");
fileOut = fileOut.replace("..",".*");
fileOut = fileOut.replace(/[.]/g,"\\.");
fileOut = fileOut.replace("web-\\.*\\.war","web.*");
echo.setMessage("undeploy pattern transformation: " + fileOut );
echo.perform( );
var undeploy_t = project.createTask("undeploy");
undeploy_t.setDynamicAttribute("undplPattern", fileOut);
undeploy_t.perform( );
]]>
</scriptdef>
called from:
<echo message="item #{file}" />
<undeploy-pattern fileIn="#{file}" directoryFile="${currentScriptDirectory}/content/custom-banklets/" />
<deployToLiferay file="#{file}" />
after this modifications it now fails when i try to set setDynamicAttribute and perform that task.
08:01:18.492: item /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.509: file name: /data/com.client-dshbrd-banklet-web-0.0.1.war
08:01:18.510: dir in /data/
08:01:18.520: undeploy pattern transformation: com\.client-dshbrd-banklet-web.*
08:01:18.528: COMMAND 'deploy-custom-banklets' FAILED (execution time: 2 seconds)
08:01:18.528: * /data/contribution.xml:250: The following error occurred while executing this line:
08:01:18.528: * /data/contribution.xml:259: required attribute undplpattern not set

I don't think you need an embedded script. I reviewed the logic and I think it would be simpler to use the ANT basename task in order to obtain the file name.
Example
├── build.xml
└── src
└── files
└── file1.war
Project run as follows
$ ant
build:
[echo] file1.war
build.xml
<project name="demo" default="build">
<target name="build">
<basename property="undeploy_name" file="src/files/file1.war"/>
<echo>${undeploy_name}</echo>
</target>
</project>

Related

Why we should write List and DetailedUser in the variable <variable type = "list<DetailedUser" name="">

I don't understand this line of the code why we have list and DetailedUser?
<data>
//app class
<import type = "com.androidistanbul.databindingdemo.layoutdetails.DetailedUser/>
// java class
<import type= "java.util.List"/>
<variable
name = "userList"
type = "detailedUser" /> // import class
<variable
name="userList"
type = "list<DetailedUser" />
</data>
// List index
<TextView
// android:layout_midth = "wrap_content"
// android:layout_height= "wrap_content"
// android:layout_marginTop = "8dp"
android:text="#{userList[index].name + "" + userList[index].surnane}"/>
< and > are html entities and they represent < and >, respectively.
So List<DetailedUser> translates to List<DetailedUser>

Email MSBuild errors - only when there are errors

msbuild MyProject.proj /fl /flp:v=detailed;logfile=mylog.txt
msbuild MyProject.proj /t:ErrorEmail
I have implemented this, and it works when there are errors.
But it's also sending an email when there are no errors.
How can I set up a condition if the file is empty, or there are 0 line count in the ReadLinesFromFile?
> <Target Name="ErrorEmail">
> <ReadLinesFromFile
> File="mylog.txt"
> Lines="_ErrorLines"
> />
> <MSBuild.Community.Tasks.Mail
> SmtpServer="mailhost.amsa.com"
> To="$(ErrorEmails)"
> From="$(FromEmail)"
> Subject="Build failure for $(SolutionName)"
> Body="Error details: #(ErrorFileContents, '%0D%0A')"
> />
> </Target>
Assuming ErrorFileContents is not empty in case of an error, you can iterate through its items to set a condition flag.
<CreateProperty Value="true">
<Output Condition="'%(ErrorFileContents.Identity)' != ''"
TaskParameter="Value"
PropertyName="SendMail" />
</CreateProperty>
<MSBuild.Community.Tasks.Mail Condition="'$(SendMail)' == true"
SmtpServer="mailhost.amsa.com"
To="$(ErrorEmails)"
From="$(FromEmail)"
Subject="Build failure for $(SolutionName)"
Body="Error details: #(ErrorFileContents, '%0D%0A')"
/>

Deploy BrowserFormWebPart declaratively without BinarySerializedWebPart Element

Does anyone know if there is a way to deploy a BrowserFormWebPart (custom InfoPath form for a list content type) using standard AllUsersWebPart element and a CDATA section for the properties? So far I have tried without success. Any help is appreciated.
After 2 days of research - Following code works
private void UpdateInfoPathForms(SPSite oSite)
{
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/newifs.aspx");
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/displayifs.aspx");
UpdateInfoPath(oSite, "Lists/Audit Calendar/Item/editifs.aspx");
}
private void UpdateInfoPath(SPSite oSite, string formFileLocation)
{
var file = oSite.RootWeb.GetFile(formFileLocation);
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared))
{
try
{
var wp1 = new Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart();
wp1.SubmitBehavior = Microsoft.Office.InfoPath.Server.Controls.WebUI.SubmitBehavior.FormDefault;
wp1.FormLocation = "~list/Item/template.xsn";
wp1.ContentTypeId = oSite.RootWeb.Lists["Audit Calendar"].ContentTypes["Item"].Id.ToString();
IListWebPart listWebpart = wp1 as IListWebPart;
listWebpart.ListId = oSite.RootWeb.Lists["Audit Calendar"].ID;
if (formFileLocation.Contains("newifs.aspx"))
{
listWebpart.PageType = PAGETYPE.PAGE_NEWFORM;
}
else if (formFileLocation.Contains("displayifs.aspx"))
{
wp1.ListFormMode = Microsoft.Office.InfoPath.Server.Controls.WebUI.ListFormMode.ReadOnly;
listWebpart.PageType = PAGETYPE.PAGE_DISPLAYFORM;
}
else if (formFileLocation.Contains("editifs.aspx"))
{
listWebpart.PageType = PAGETYPE.PAGE_EDITFORM;
}
listWebpart.ViewFlags = SPViewFlags.None;
manager.AddWebPart(wp1, "Main", 0);
manager.SaveChanges(wp1);
}
finally
{
manager.Web.Dispose();
}
}
I have had the same problem. Here is what I tried:
<AllUsersWebPart WebPartZoneID="Main" WebPartOrder="2">
<![CDATA[
<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="Microsoft.Office.InfoPath.Server.Controls.WebUI.BrowserFormWebPart, Microsoft.Office.InfoPath.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="ChromeType" type="chrometype">None</property>
<property name="HelpMode" type="helpmode">Modeless</property>
<property name="ChromeState" type="chromestate">Normal</property>
</properties>
</data>
</webPart>
</webParts>]]>
</AllUsersWebPart>
I then have a Feature Receiver that configures the web part:
using (SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
try
{
BrowserFormWebPart webpart = GetWebPart(manager);
webpart.SubmitBehavior = SubmitBehavior.FormDefault;
webpart.FormLocation = "~list/MyList/template.xsn";
webpart.ContentTypeId = "0x01003C8AD6E14DAD5342BBFAA84E63F8022C";
manager.SaveChanges(webpart);
}
finally
{
manager.Web.Dispose();
}
}
The BrowserFormWebPart properties are required for getting the form to display, but for some reason, setting those properties in the AllUsersWebPart section did not work. The form displays and I can fill it out, but the values from the form do not get inserted into the fields of the list item. I added the following section to the Feature Receiver to try to get the form to tie into the fields of the list item:
IListWebPart listWebpart = webpart as IListWebPart;
listWebpart.PageType = PAGETYPE.PAGE_EDITFORM;
listWebpart.ViewFlags = SPViewFlags.None;
Unfortunately, no joy. And that is as far as I got. Hopefully you'll have better luck.

msbuild solution file

I have created a msbuild file which will build a solution file(NOTE: not a project file). I would like to be able to change the debug and release target path in the msbuild file. How can i go about doing that? Thank you very much.
msbuild file
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="deploy">
<MSBuild Projects="foo.sln" Properties="Configuration=Release" ContinueOnError="false" />
</Target>
</Project>
Solution file Below:
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "foo", ".", "{3D958438-10F1-4211-BC7F-F0A5E5601C3F}"
ProjectSection(WebsiteProperties) = preProject
TargetFramework = "3.5"
Debug.AspNetCompiler.VirtualPath = "/foo"
Debug.AspNetCompiler.PhysicalPath = "..\foo\"
Debug.AspNetCompiler.TargetPath = "..\..\PrecompiledWeb\foo\"
Debug.AspNetCompiler.Updateable = "true"
Debug.AspNetCompiler.ForceOverwrite = "true"
Debug.AspNetCompiler.FixedNames = "false"
Debug.AspNetCompiler.Debug = "True"
Release.AspNetCompiler.VirtualPath = "/foo"
Release.AspNetCompiler.PhysicalPath = "..\foo\"
Release.AspNetCompiler.TargetPath = "..\..\PrecompiledWeb\foo\"
Release.AspNetCompiler.Updateable = "true"
Release.AspNetCompiler.ForceOverwrite = "true"
Release.AspNetCompiler.FixedNames = "false"
Release.AspNetCompiler.Debug = "False"
VWDPort = "51644"
DefaultWebSiteLanguage = "Visual Basic"
EndProjectSection
EndProject
To change the output, set the OutDir property. So instead of:
Properties="Configuration=Release"
try:
Properties="Configuration=Release;OutDir=d:\myCode\out\"

How to read the assemblyversion from assemblyInfo.cs?

Hii,
there are many others had already post so many question about this..But here the scenario is different.
I need to extract the first three digits ie. $(major).$(Minor).$(Build) from version number.
how can i do this??..i tried AssemblyInfo Task..but that task is just for overwriting the version number.not to extract the version number.
I need to extract first three number and assign them to some property.for further use.
well,i can overwrite them using FileUpdate task.like ::
<FileUpdate
Files="#(AssemblyFile)"
Regex='(\d+)\.(\d+)\.(\d+)\.(\d+)'
ReplacementText='$1.$2.$3.$(Revision)'>
</FileUpdate>
now how can i use their value ie. $1,$2,$3 to assign to properties.???
Thanx.
You can read lines from files, get the string using regex and change it if you need. And if you're using MSBuild 4.0 you can use Property Functions, which give you an access to .NET API.
This example should give you first three numbers of the AssemblyVersion.
<Target Name="ReadAssemblyVersion">
<ReadLinesFromFile File="$(VersionFile)">
<Output TaskParameter="Lines"
ItemName="ItemsFromFile"/>
</ReadLinesFromFile>
<PropertyGroup>
<Pattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+)</Pattern>
<In>#(ItemsFromFile)</In>
<Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
</PropertyGroup>
<Message Text="Output : $(Out.Remove(0, 28))"/>
</Target>
http://blogs.msdn.com/b/visualstudio/archive/2010/04/02/msbuild-property-functions.aspx
Awesome thread, building upon the work of Alex and RobPol, I was able to define extended msbuild properties that is inspired by semver.org (Major, Minor, Patch, PreRelease). I chose to parse the AssemblyInformalVersion since that is the only attribute compatible with SemVer. Here is My example:
<PropertyGroup>
<In>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs'))</In>
<Pattern>\[assembly: AssemblyInformationalVersion\("(?<Major>\d+)\.(?<Minor>\d+)\.(?<Patch>[\d]+)(?<PreReleaseInfo>[0-9A-Za-z-.]+)?</Pattern>
<AssemblyVersionMajor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["Major"].Value)</AssemblyVersionMajor>
<AssemblyVersionMinor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["Minor"].Value)</AssemblyVersionMinor>
<AssemblyVersionPatch>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["Patch"].Value)</AssemblyVersionPatch>
<AssemblyVersionPreRelease>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups["PreReleaseInfo"].Value)</AssemblyVersionPreRelease>
</PropertyGroup>
You can test the output of this operation by adding the following to your .csproj:
<Target Name="AfterBuild">
<Message Text="$(AssemblyVersionMajor)"></Message>
<Message Text="$(AssemblyVersionMinor)"></Message>
<Message Text="$(AssemblyVersionPatch)"></Message>
<Message Text="$(AssemblyVersionPreRelease)"></Message>
</Target>
Ex: Snippet from my AssemblyInfo.cs:
[assembly: AssemblyInformationalVersion("0.9.1-beta")]
Will output: Major: '0', Minor: '9', Patch: '1', PreRelease: '-beta'
Building on Alex's answer, I used RegEx to read the AssemblyVersion (and other information) and use that in my WiX/MSI filename and version strings. Hopefully my answer isn't too noisy.
Here is the top of my .wixproj file. Points of interest are the first PropertyGroup, OutputName, and DefineConstants:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<In>$([System.IO.File]::ReadAllText('$(MSBuildProjectDirectory)\..\MyApplication\Properties\AssemblyInfoCommon.cs'))</In>
<Pattern>^\s*\[assembly: AssemblyVersion\(\D*(\d+)\.(\d+)\.(\d+)</Pattern>
<AssemblyVersionMajor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyVersionMajor>
<AssemblyVersionMinor>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[2].Value)</AssemblyVersionMinor>
<AssemblyVersionBuild>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[3].Value)</AssemblyVersionBuild>
<Pattern>^\s*\[assembly: AssemblyDescription\(\s*"([^"]+)"</Pattern>
<AssemblyDescription>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyDescription>
<Pattern>^\s*\[assembly: AssemblyProduct\(\s*"([^"]+)"</Pattern>
<AssemblyProduct>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyProduct>
<Pattern>^\s*\[assembly: AssemblyCompany\(\s*"([^"]+)"</Pattern>
<AssemblyCompany>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern), System.Text.RegularExpressions.RegexOptions.Multiline).Groups[1].Value)</AssemblyCompany>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>3.7</ProductVersion>
<ProjectGuid>MYGUID00-840B-4055-8251-F2B83BC5DBB9</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>$(AssemblyProduct)-$(AssemblyVersionMajor).$(AssemblyVersionMinor).$(AssemblyVersionBuild)</OutputName>
<OutputType>Package</OutputType>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug;AssemblyVersionMajor=$(AssemblyVersionMajor);AssemblyVersionMinor=$(AssemblyVersionMinor);AssemblyVersionBuild=$(AssemblyVersionBuild);AssemblyDescription=$(AssemblyDescription);AssemblyProduct=$(AssemblyProduct);AssemblyCompany=$(AssemblyCompany)</DefineConstants>
<SuppressValidation>False</SuppressValidation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>AssemblyVersionMajor=$(AssemblyVersionMajor);AssemblyVersionMinor=$(AssemblyVersionMinor);AssemblyVersionBuild=$(AssemblyVersionBuild);AssemblyDescription=$(AssemblyDescription);AssemblyProduct=$(AssemblyProduct);AssemblyCompany=$(AssemblyCompany)</DefineConstants>
</PropertyGroup>
And then in a .wxi file I have this:
<?define MajorVersion="$(var.AssemblyVersionMajor)" ?>
<?define MinorVersion="$(var.AssemblyVersionMinor)" ?>
<?define BuildVersion="$(var.AssemblyVersionBuild)" ?>
<?define VersionNumber="$(var.MajorVersion).$(var.MinorVersion).$(var.BuildVersion)" ?>
And finally in my Product.wxs:
<?include Definitions.wxi ?>
<Product Id="$(var.GuidProduct)" Name="$(var.AssemblyProduct) $(var.VersionNumber)" Language="!(loc.LANG)"
Version="$(var.VersionNumber)" Manufacturer="$(var.AssemblyCompany)" UpgradeCode="$(var.GuidUpgrade)">
<Package Id="$(var.GuidPackage)" InstallerVersion="301" Compressed="yes" InstallScope="perMachine"
Keywords="!(loc.Keywords)" Description="$(var.AssemblyProduct)" Comments="$(var.AssemblyDescription)" />
If you want to be able to process your AssemblyInfo file with 100% accuracy you can use a C# task + Roslyn.
public class ReadAssemblyInfo : Task {
[Required]
public string AssemblyInfoFilePath { get; set; }
[Output]
public TaskItem AssemblyVersion { get; set; }
[Output]
public TaskItem AssemblyInformationalVersion { get; set; }
[Output]
public TaskItem AssemblyFileVersion { get; set; }
public override bool Execute() {
using (var reader = new StreamReader(AssemblyInfoFilePath)) {
var text = reader.ReadToEnd();
var tree = CSharpSyntaxTree.ParseText(text);
var root = (CompilationUnitSyntax)tree.GetRoot();
var attributeLists = root.DescendantNodes().OfType<AttributeListSyntax>();
foreach (var p in attributeLists) {
foreach (var attribute in p.Attributes) {
var identifier = attribute.Name as IdentifierNameSyntax;
if (identifier != null) {
var value = ParseAttribute("AssemblyInformationalVersion", identifier, attribute);
if (value != null) {
SetMetadata(AssemblyInformationalVersion = new TaskItem(value.ToString()), value);
break;
}
value = ParseAttribute("AssemblyVersion", identifier, attribute);
if (value != null) {
SetMetadata(AssemblyVersion = new TaskItem(value.ToString()), value);
break;
}
value = ParseAttribute("AssemblyFileVersion", identifier, attribute);
if (value != null) {
SetMetadata(AssemblyFileVersion = new TaskItem(value.ToString()), value);
break;
}
}
}
}
}
return !Log.HasLoggedErrors;
}
private void SetMetadata(TaskItem taskItem, Version version) {
taskItem.SetMetadata(nameof(version.Major), version.Major.ToString());
taskItem.SetMetadata(nameof(version.Minor), version.Minor.ToString());
taskItem.SetMetadata(nameof(version.Build), version.Build.ToString());
taskItem.SetMetadata(nameof(version.Revision), version.Revision.ToString());
}
private static Version ParseAttribute(string attributeName, IdentifierNameSyntax identifier, AttributeSyntax attribute) {
if (identifier.Identifier.Text.IndexOf(attributeName, StringComparison.Ordinal) >= 0) {
AttributeArgumentSyntax listArgument = attribute.ArgumentList.Arguments[0];
var rawText = listArgument.Expression.GetText().ToString();
if (!string.IsNullOrWhiteSpace(rawText)) {
rawText = rawText.Replace("\"", "");
Version version;
if (Version.TryParse(rawText, out version)) {
return version;
}
}
}
return null;
}
}
I just found this on google, might help:
http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.version%28v=VS.90%29.aspx
Particularly:
//For AssemblyFileVersion
Assembly asm = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
string version = fvi.FileVersion
//For AssemblyVersion
string revision = Assembly.GetExecutingAssembly().GetName().Version.Revision;
You can use MSBuild.Community.Tasks.AssemblyInfo.AssemblyVersion to access AssemblyVersion and AssemblyFileVersion from AssemblyInfo.cs.
Indeed this task can only be used to set the version.
Maybe this post is usefull.
I use the RegexMatch-task from the MSBuild.Community.Tasks.
You can write the output of the match to an itemgroup, although you want to read it into 3 properties, as above, a custom task would then be prefered.
The only solution is to write a custom build task, and parse the version number manually in the code.