Return output from an MsBuild task?

Use a property or an item. Your MSBuild that calculates the path, return it as a property and you use this property as input for your other task. public class CalculatePathTask : ITask { [Output] public String Path { get; set; } public bool Execute() { Path = CalculatePath(); return true; } } <Target Name=”CalculateAndUsePath”> … Read more

how to replace string in file using msbuild?

This is no longer required… you can now inject C# into the project/build file… Define a custom task and parameters as follows: <UsingTask TaskName=”ReplaceFileText” TaskFactory=”CodeTaskFactory” AssemblyFile=”$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll”> <ParameterGroup> <InputFilename ParameterType=”System.String” Required=”true” /> <OutputFilename ParameterType=”System.String” Required=”true” /> <MatchExpression ParameterType=”System.String” Required=”true” /> <ReplacementText ParameterType=”System.String” Required=”true” /> </ParameterGroup> <Task> <Reference Include=”System.Core” /> <Using Namespace=”System” /> <Using Namespace=”System.IO” /> <Using … Read more

What is the difference between a PreBuildEvent, BeforeBuild target and BeforeCompile target in MSBuild?

The answer to this question can be found in the Microsoft.Common.targets file which can be found (depending on wether you’re using the 64-bit or 32-bit framework) at: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.target for 64-bit and C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets for the 32-bit runtime. This file defines all the steps a build of your project undergoes. Quoting the source: <!– ============================================================ Build The … Read more

How get exec task output with msbuild

Good news everyone! You can now capture output from <Exec> as of .NET 4.5. Like this: <Exec … ConsoleToMSBuild=”true”> <Output TaskParameter=”ConsoleOutput” PropertyName=”OutputOfExec” /> </Exec> Simply: Add ConsoleToMsBuild=”true” to your <Exec> tag Capture the output using the ConsoleOutput parameter in an <Output> tag Finally! Documentation here