JohnnyBoyWonder

I would like to apply 'some' changes to the many AssemblyInfo.cs files in our project as part of continuous integration using CCnet.

However, when I use the AssemblyInfo task it seems to only write those values I set using the task. So, how do I read the original AssemblyInfo.cs files, grab the values I want to keep - like [assembly: Guid("blah")], etc, so that I can write them back into the new file I create just before compile

Currently,
1. I copy the original AssemblyInfo.cs
2. Use the AssemblyInfo task to create the 'new' AssemblyInfo.cs
3. Compile all the projects
4. Delete the 'new' AssemblyInfo.cs
5. Copy the original back

Any links, hints, etc would be welcome



Re: Visual Studio MSBuild AssemblyInfo task - use exiting AssemblyInfo.cs values in new file.

JohnnyBoyWonder

Ok, so what you wanted to say was write a simple custom task dll, eh

So i did, like this

Code Snippet

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;



namespace StringManipulation.Tools.MSBuildTasks
{
public class SimpleTask : Task
{
private String InputString;
private String AttributeString;
private String ReturnStringValue;

public override bool Execute()
{
int iStartChr;
int iEndChr;
int iAttributeString;
int iNewStringLength;
iAttributeString = AttributeString.Length;
//Log.LogMessage("AttributeString is " + iAttributeString + " long");
iStartChr = InputString.IndexOf(AttributeString) + 2 + iAttributeString;
iEndChr = InputString.IndexOf("\"", iStartChr);
iNewStringLength = iEndChr - iStartChr;
//Log.LogMessage("ReturnStringValue is " + iNewStringLength + " long");
ReturnStringValue = InputString.Substring(iStartChr, iNewStringLength);
return true;
}
[Required]
public string SourceString
{
get { return InputString; }
set { InputString = value; }
}

[Required]
public string AssemblyInfoAttribute
{
get { return AttributeString; }
set { AttributeString = value; }
}

[Output]
public string AttributeValue
{
get { return ReturnStringValue; }
set { ReturnStringValue = value; }
}


}
}



With a msbuild like this to use it.

Code Snippet

<Target Name="Build">

<ReadLinesFromFile File="AssemblyInfo.cs">
<Output PropertyName="MyText" TaskParameter="Lines" />
</ReadLinesFromFile>
<SimpleTask SourceString="$(mytext)" AssemblyInfoAttribute="Guid" >
<Output TaskParameter="AttributeValue" ItemName="OutPuttedText" />
</SimpleTask>
<Message Text="@(OutPuttedText)" />
</Target>