Can someone write (or link to) a walkthrough that explains exactly how to create a custom MSBuild task and run it during a build? I'm looking for a custom task that inherits from Microsoft.Build.Utilities.Task and does only this:
public override bool Execute()
{
Log.LogMessage("Hello world!");
return true;
}
(I've been working on this for hours and keep getting the "The [whatever] task was not found. Check the following" message. I think I must be missing an essential step somewhere. If there's a clear tutorial I can follow, perhaps I'll figure out where I'm falling short.)
Are you declaring your custom task in your MSBuild project file? You need a line like this:
<UsingTask AssemblyFile="C:\PathTo\MyTasks.dll" TaskName="MyTasks.HelloWord" />
Then MSBuild can execute your task.
See
Best Practices For Creating Reliable Builds section Creating Custom Tasks.
THE CUSTOM MSBUILD TASK COOKBOOK from Bart De Smet
Related
I am trying to build my .net solution using cake build file. I am trying to use the documentation on the website here
My current msbuild task looks like this:
MSBuild("./solution.sln", new MSBuildSettings()
.SetConfiguration(environmentSetting)
.SetMSBuildPlatform(MSBuildPlatform.Automatic)
.SetVerbosity(Verbosity.Minimal)
.SetMaxCpuCount(System.Environment.ProcessorCount)
.SetNodeReuse(false)
.WithConsoleLoggerParameter("ErrorsOnly"));
It keeps throwing error for the parameter .WithConsoleLoggerParameter. I am not sure what am I doing wrong here.
The Microsoft documentation shows here the same thing and I tried running it in powershell with the same parameters and it ran just file.
Actually I figured it out. I am not sure how the argument customization works so any explanation for that would be great!
I changed the code to
MSBuild("./solution.sln", new MSBuildSettings(){
ArgumentCustomization = args=>args.Append("/consoleloggerparameters:ErrorsOnly")
}
.SetConfiguration(environmentSetting)
.SetMSBuildPlatform(MSBuildPlatform.Automatic)
.SetVerbosity(Verbosity.Minimal)
.SetMaxCpuCount(System.Environment.ProcessorCount)
.SetNodeReuse(false));
Seems to work. Hope this helps someone!
I have a project that I'm working on and I wanted to double check before going through the work of coding and testing if this was even possible. What I'm attempting to do is something along the lines of:
try {
// Do stuff
try {
// Do other stuff
}
catch {
// Fail silently
}
// Do more stuff
}
catch (...) {
// Process error
}
Is it possible to have try/catch's within try/catch's? Most languages allow this but when I attempted to search the web I could not, for the life of me, find any answers.
Thanks
An SSIS script task is C# (or VB.NET). C# allows this, ergo SSIS allows this.
Having written a few SSIS Script Tasks in my time, I'd encourage you to take advantage of Raising Events in the Script Task.
Depending on your version + deployment model + invocation method, you might want to also turn on the native SSIS Logging. Project Deployment Model (in 2012+) provides native logging. Otherwise, you will need to specify the events you'd like to log as well as the logging provider(s) you'd like to use with them. This would need to be done as part of package development. Otherwise, I like a DTEXEC call with /REP EWI will ensure Errors, Warnings and Information events are logged to the console/SQL Agent.
I added a custom workflow argument using the steps outlined here. Now, how do I read the value of this argument from the custom MSBuild script I have included in the build definition that uses this custom workflow?
UPDATE:
There really is no need to add a custom argument to the workflow. Following the steps below I was able to pass an argument to the MSBuild script for a Exec command.
In the build definiton under MSBuildArguments, add /p:CommandArg=dev
In the custom MSBuild script add a new property <CommandArg>placeholder</CommandArg>
Edit Exec command to be: <Exec Command=CALL run.cmd $(CommandArg)/>
You need to alter the MSBuild Workflow Activity Parameters to include your new argument. If you search your XAML workflow for mtbwa:MSBuild you should be able to clearly see how the CommandLine build arguments are being build via a String.Format and add your parameter to the set of arguments passed in.
I need to embed, invoke and run some custom code as part of my custom managed bootstrapper application, as a post-install step. This custom code is within a class library that I have included as a reference in my MBA project. So, right after the state becomes InstallationState.Applied I plan on invoking this custom code. However, I am unable to figure out how I could tie in a failed state of this custom code to initiate the bootstrapper to rollback, since the progress callback would have been completed by now. Any ideas?
As per WiX & Burn's lead dev Rob Mensching here, point-2, it seems any custom code that needs to facilitate rollback in the setup process should be run as a custom action, and not as part of the bootstrapper application, as I wanted to. I went ahead and did as Rob suggested, and everything works as expected. However, since the custom action runs significant code, I may in future put that in a WiX extension.
This has got to be a lamer question:
In my test project I am attempting to configure log4net. The following method call gives the error.
BasicConfigurator.Configure();
"type name expected but method found"
What am I overlooking?
Thanks,
Nick
Is this a compile time error or runtime error? Do you have a using log4net.Config statement in your class file? Does it still happen if you change it to reference the full class name?
log4net.Config.BasicConfigurator.Configure();
I'm not sure if linking to blog entries is verboten...
If you are trying to log NHibernate stuff, here is what I do:
How to show Log4Net info in NUnit (from NHibernate)
I also have a more basic getting started guide here:
Getting Started with Log4Net
oops.. I was trying to do this in the wrong context. I added the method call to my test project's constructor and we're good.