This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a file `~\header.cs` with the copyright or whatever you want | |
# in each file. Then run this script. | |
# | |
# Notes: | |
# | |
# Second step will force BOM at the start, and newline at the end, of each | |
# file. It will also push all file encodings to be the same. Those make | |
# diffs a little ugly. | |
# | |
# So, I do it in two steps: one to normalize encoding, and one to actually |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyTask : Task | |
{ | |
[Required] | |
public string Foo { get; set; } | |
public override bool Execute() | |
{ | |
Log.LogMessage(MessageImportance.Low, "Inputs:"); | |
Log.LogMessage(MessageImportance.Low, " Foo = {0}", this.Foo); | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<UsingTask TaskName="MyTask" AssemblyFile=".\bin\Debug\ClassLibrary2.dll" /> | |
<Target Name="Build"> | |
<MyTask Foo = "hi" /> | |
</Target> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS> msbuild .\My.proj /v:d | |
... | |
Task "MyTask" | |
Inputs: | |
Foo = hi | |
Done executing task "MyTask". | |
PS> msbuild .\My.proj /v:diag | |
... | |
Task "MyTask" (TaskId:2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void TestMethod1() | |
{ | |
var process = new Process | |
{ | |
StartInfo = | |
{ | |
FileName = @"C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe", | |
Arguments = @"..\..\my.proj /v:m /nologo", | |
UseShellExecute = false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HighImportanceStringLogger : ILogger | |
{ | |
readonly private StringBuilder stringBuilder = new StringBuilder(); | |
public void Initialize(IEventSource eventSource) | |
{ | |
eventSource.MessageRaised += eventSource_MessageRaised; | |
} | |
void eventSource_MessageRaised(object sender, BuildMessageEventArgs e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myProject = new ProjectInstance(@"..\..\my.proj"); | |
var logger = new HighImportanceStringLogger(); | |
var success = myProject.Build(new[] { logger }); | |
Assert.IsTrue(success); | |
const string expected = @"Inputs: | |
Foo = hi | |
"; | |
Assert.AreEqual(expected, logger.ToString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var projectRootElement = ProjectRootElement.Create(); | |
projectRootElement.AddUsingTask(typeof (MyTask)); | |
projectRootElement | |
.AddTarget("Build") | |
.AddTask(typeof(MyTask).Name) | |
.SetParameter("Foo", "hi"); | |
var highImportanceStringLogger = new HighImportanceStringLogger(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Build.Construction; | |
public static class ProjectRootElementExtensions | |
{ | |
public static void AddUsingTask(this ProjectRootElement projectRootElement, Type type) | |
{ | |
projectRootElement | |
.AddUsingTask(type.Name, type.Assembly.Location, null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using Microsoft.Build.Construction; | |
static class ProjectTargetElementExtensions | |
{ | |
public static ProjectTaskElement AddTask<TTask>(this ProjectTargetElement projectTargetElement) | |
{ | |
string taskName = typeof (TTask).Name; | |
ProjectRootElement projectRootElement = projectTargetElement.ContainingProject; |
OlderNewer