forked from dotnet/msbuild
/
CustomLogAndReturnTask.cs
39 lines (32 loc) · 1.22 KB
/
CustomLogAndReturnTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.Build.UnitTests
{
public class CustomLogAndReturnTask : Task
{
public string WarningCode { get; set; }
public string ErrorCode { get; set; }
public bool ReturnHasLoggedErrors { get; set; }
[Required]
public bool Return { get; set; }
// Unused for now, created for task batching.
public ITaskItem[] Sources { get; set; }
/// <summary>
/// This task returns and logs what you want based on the running test.
/// </summary>
public override bool Execute()
{
if(!string.IsNullOrEmpty(WarningCode))
{
Log.LogWarning(null, WarningCode, null, null, 0, 0, 0, 0, "Warning Logged!", null);
}
if(!string.IsNullOrEmpty(ErrorCode))
{
Log.LogError(null, ErrorCode, null, null, 0, 0, 0, 0, "Error Logged!", null);
}
return ReturnHasLoggedErrors ? !Log.HasLoggedErrors : Return;
}
}
}