Skip to content

Commit 2b6462c

Browse files
committed
Add the MS build messages to AzDo logs
1 parent 2c626de commit 2b6462c

File tree

2 files changed

+68
-43
lines changed

2 files changed

+68
-43
lines changed

scripts/cake/UtilsManaged.cake

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,6 @@ var UNSUPPORTED_TESTS = new Dictionary<string, string>
1515
{ "SkipOn", skipTestOnPlatform },
1616
};
1717

18-
void RunDotNetPack(
19-
FilePath solution,
20-
DirectoryPath outputPath = null,
21-
string bl = ".pack",
22-
string configuration = null,
23-
string additionalArgs = null,
24-
Dictionary<string, string> properties = null)
25-
{
26-
EnsureDirectoryExists(OUTPUT_NUGETS_PATH);
27-
28-
var c = new DotNetPackSettings();
29-
var msb = new DotNetMSBuildSettings();
30-
c.MSBuildSettings = msb;
31-
32-
c.Configuration = configuration ?? CONFIGURATION;
33-
c.Verbosity = DotNetVerbosity.Minimal;
34-
35-
var relativeSolution = MakeAbsolute(ROOT_PATH).GetRelativePath(MakeAbsolute(solution));
36-
var blPath = ROOT_PATH.Combine("output/logs/binlogs").CombineWithFilePath(relativeSolution + bl + ".binlog");
37-
msb.BinaryLogger = new MSBuildBinaryLoggerSettings {
38-
Enabled = true,
39-
FileName = blPath.FullPath,
40-
};
41-
42-
c.NoBuild = true;
43-
44-
c.OutputDirectory = outputPath ?? OUTPUT_NUGETS_PATH;
45-
46-
msb.Properties ["NoDefaultExcludes"] = new [] { "true" };
47-
48-
if (properties != null) {
49-
foreach (var prop in properties) {
50-
if (!string.IsNullOrEmpty(prop.Value)) {
51-
msb.Properties [prop.Key] = new [] { prop.Value };
52-
}
53-
}
54-
}
55-
56-
c.ArgumentCustomization = args => args.Append(additionalArgs);
57-
58-
DotNetPack(solution.FullPath, c);
59-
}
60-
6118
void RunTests(FilePath testAssembly, DirectoryPath output, bool is32)
6219
{
6320
var dir = testAssembly.GetDirectory();

scripts/cake/msbuild.cake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ string[] GetNuGetSources()
2828
return adds.ToArray();
2929
}
3030

31+
ProcessArgumentBuilder AppendForwardingLogger(ProcessArgumentBuilder args)
32+
{
33+
if (BuildSystem.IsLocalBuild)
34+
return args;
35+
36+
// URL copied from https://github.com/microsoft/azure-pipelines-tasks/blob/7faf3e8146d43753b9f360edfae3d2e75ad78c76/Tasks/DotNetCoreCLIV2/make.json
37+
var loggerUrl = "https://vstsagenttools.blob.core.windows.net/tools/msbuildlogger/3/msbuildlogger.zip";
38+
39+
var AGENT_TEMPDIRECTORY = (DirectoryPath)EnvironmentVariable("AGENT_TEMPDIRECTORY");
40+
var loggerDir = AGENT_TEMPDIRECTORY.Combine("msbuildlogger");
41+
EnsureDirectoryExists(loggerDir);
42+
43+
var loggerZip = loggerDir.CombineWithFilePath("msbuildlogger.zip");
44+
if (!FileExists(loggerZip))
45+
DownloadFile(loggerUrl, loggerZip);
46+
47+
var loggerDll = loggerDir.CombineWithFilePath("Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll");
48+
if (!FileExists(loggerDll))
49+
Unzip(loggerZip, loggerDir);
50+
51+
return args.Append($"-dl:CentralLogger,\"{loggerDll}\"*ForwardingLogger,\"{loggerDll}\"");
52+
}
53+
3154
void RunNuGetRestorePackagesConfig(FilePath sln)
3255
{
3356
var dir = sln.GetDirectory();
@@ -160,6 +183,51 @@ void RunDotNetBuild(
160183
}
161184
}
162185
c.Sources = GetNuGetSources();
186+
187+
c.ArgumentCustomization = AppendForwardingLogger;
163188

164189
DotNetBuild(solution.FullPath, c);
165190
}
191+
192+
void RunDotNetPack(
193+
FilePath solution,
194+
DirectoryPath outputPath = null,
195+
string bl = ".pack",
196+
string configuration = null,
197+
string additionalArgs = null,
198+
Dictionary<string, string> properties = null)
199+
{
200+
EnsureDirectoryExists(OUTPUT_NUGETS_PATH);
201+
202+
var c = new DotNetPackSettings();
203+
var msb = new DotNetMSBuildSettings();
204+
c.MSBuildSettings = msb;
205+
206+
c.Configuration = configuration ?? CONFIGURATION;
207+
c.Verbosity = DotNetVerbosity.Minimal;
208+
209+
var relativeSolution = MakeAbsolute(ROOT_PATH).GetRelativePath(MakeAbsolute(solution));
210+
var blPath = ROOT_PATH.Combine("output/logs/binlogs").CombineWithFilePath(relativeSolution + bl + ".binlog");
211+
msb.BinaryLogger = new MSBuildBinaryLoggerSettings {
212+
Enabled = true,
213+
FileName = blPath.FullPath,
214+
};
215+
216+
c.NoBuild = true;
217+
218+
c.OutputDirectory = outputPath ?? OUTPUT_NUGETS_PATH;
219+
220+
msb.Properties ["NoDefaultExcludes"] = new [] { "true" };
221+
222+
if (properties != null) {
223+
foreach (var prop in properties) {
224+
if (!string.IsNullOrEmpty(prop.Value)) {
225+
msb.Properties [prop.Key] = new [] { prop.Value };
226+
}
227+
}
228+
}
229+
230+
c.ArgumentCustomization = args => AppendForwardingLogger(args).Append(additionalArgs);
231+
232+
DotNetPack(solution.FullPath, c);
233+
}

0 commit comments

Comments
 (0)