Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

#1091 Quote path to DotNetWatch.targets #1210

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions src/Microsoft.Tye.Hosting/Watch/Internal/MsBuildFileSetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class MsBuildFileSetFactory : IFileSetFactory
{
private const string TargetName = "GenerateWatchList";
private const string WatchTargetsFileName = "DotNetWatch.targets";
private readonly bool _waitOnError;
private readonly ILogger _logger;
private readonly string _projectFile;
private readonly bool _waitOnError;
private readonly IReadOnlyList<string> _buildFlags;
private readonly bool _trace;

public MsBuildFileSetFactory(ILogger reporter,
string projectFile,
Expand All @@ -39,7 +39,7 @@ internal MsBuildFileSetFactory(ILogger logger,
{
_logger = logger;
_projectFile = projectFile;
_buildFlags = InitializeArgs(FindTargetsFile(), trace);
_trace = trace;
}

public async Task<IFileSet> CreateAsync(CancellationToken cancellationToken)
Expand All @@ -53,19 +53,11 @@ public async Task<IFileSet> CreateAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

var args = new StringBuilder();
args.Append($"msbuild \"{_projectFile}\" /p:_DotNetWatchListFile=\"{watchList}\"");
foreach (var flag in _buildFlags)
{
args.Append(" ");
args.Append(flag);
}

var processSpec = new ProcessSpec
{
Executable = "dotnet",
WorkingDirectory = projectDir!,
Arguments = args.ToString()
Arguments = GetArgs(watchList!),
WorkingDirectory = projectDir!
};

_logger.LogDebug($"Running MSBuild target '{TargetName}' on '{_projectFile}'");
Expand Down Expand Up @@ -128,26 +120,30 @@ public async Task<IFileSet> CreateAsync(CancellationToken cancellationToken)
}
}

private IReadOnlyList<string> InitializeArgs(string watchTargetsFile, bool trace)
private string GetArgs(string watchList)
{
var watchTargetsFile = FindTargetsFile();

var args = new List<string>
{
$"msbuild \"{_projectFile}\"",
$"/p:_DotNetWatchListFile=\"{watchList}\"",
"/nologo",
"/v:n",
"/t:" + TargetName,
$"/t:{TargetName}",
"/p:DotNetWatchBuild=true", // extensibility point for users
"/p:DesignTimeBuild=true", // don't do expensive things
"/p:CustomAfterMicrosoftCommonTargets=" + watchTargetsFile,
"/p:CustomAfterMicrosoftCommonCrossTargetingTargets=" + watchTargetsFile,
$"/p:CustomAfterMicrosoftCommonTargets=\"{watchTargetsFile}\"",
$"/p:CustomAfterMicrosoftCommonCrossTargetingTargets=\"{watchTargetsFile}\"",
};

if (trace)
if (_trace)
{
// enables capturing markers to know which projects have been visited
args.Add("/p:_DotNetWatchTraceOutput=true");
}

return args;
return string.Join(" ", args);
}

private string FindTargetsFile()
Expand All @@ -164,9 +160,10 @@ private string FindTargetsFile()
var targetPath = searchPaths.Select(p => Path.Combine(p, WatchTargetsFileName)).FirstOrDefault(File.Exists);
if (targetPath == null)
{
_logger.LogError("Fatal error: could not find DotNetWatch.targets");
_logger.LogError($"Fatal error: could not find {WatchTargetsFileName}");
return null!;
}

return targetPath;
}
}
Expand Down