Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<!-- VS for Mac may run on a lower version of .NET than the SDK is targeting, but needs to load the resolvers. So the resolvers and dependencies
may target a lower version of .NET -->
<ResolverTargetFramework>net6.0</ResolverTargetFramework>
<!-- Source build does not need to worry about running on VS for Mac -->
<ResolverTargetFramework Condition="'$(DotNetBuildFromSource)' == 'true'">$(SdkTargetFramework)</ResolverTargetFramework>

<!-- Disable implict package target fallback, and disable warning for when we explicitly add it (currently needed for
Microsoft.ApplicationInsights) -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">net7.0;net472</TargetFrameworks>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we build net472 when source building?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to keep source-build as close to the product build as possible. If we don't lose anything by dropping net472 here, I'm fine with removing it though.

<IsPackable>true</IsPackable>
<IsShippingPackage>true</IsShippingPackage>
<StrongNameKeyId>Open</StrongNameKeyId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<Project>
<PropertyGroup>
<DotNetApiCompatTaskAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net472\Microsoft.DotNet.ApiCompat.Task.dll</DotNetApiCompatTaskAssembly>
<DotNetApiCompatTaskAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\net6.0\Microsoft.DotNet.ApiCompat.Task.dll</DotNetApiCompatTaskAssembly>
<DotNetApiCompatTaskAssembly Condition="'$(MSBuildRuntimeType)' == 'Core' and Exists('$(MSBuildThisFileDirectory)..\tools\net7.0\Microsoft.DotNet.ApiCompat.Task.dll')">$(MSBuildThisFileDirectory)..\tools\net7.0\Microsoft.DotNet.ApiCompat.Task.dll</DotNetApiCompatTaskAssembly>
<DotNetApiCompatTaskAssembly Condition="'$(MSBuildRuntimeType)' == 'Core' and $(DotNetApiCompatTaskAssembly)' == ''">$(MSBuildThisFileDirectory)..\tools\net6.0\Microsoft.DotNet.ApiCompat.Task.dll</DotNetApiCompatTaskAssembly>
<UseApiCompatPackage>true</UseApiCompatPackage>
<!-- TODO: Remove when the consumers of this package upgraded to a newer SDK with this change. -->
<UseCompatibilityPackage>true</UseCompatibilityPackage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition="'$(DotNetBuildFromSource)' == 'true'">net7.0</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">net7.0;net472</TargetFrameworks>
<StrongNameKeyId>Open</StrongNameKeyId>
<Nullable>enable</Nullable>
<!-- We need to compare ISymbols in a special way (by name) and roslyn symbol comparers take more heuristics into consideration.-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<TargetFrameworks Condition="'$(DotNetBuildFromSource)' == 'true'">net7.0;net472</TargetFrameworks>
<StrongNameKeyId>Open</StrongNameKeyId>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Intentionally pinned. This feature is supported in projects targeting 6.0 or newer.-->
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>

<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion src/Layout/redist/targets/GenerateLayout.targets
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
<ItemGroup>
<DotNetWatchFile Include="$(ArtifactsDir)bin\dotnet-watch\$(Configuration)\$(SdkTargetFramework)\**" />
<DotNetWatchFile Include="$(ArtifactsDir)bin\Microsoft.AspNetCore.Watch.BrowserRefresh\$(Configuration)\netcoreapp3.1\*.dll" DeploymentSubpath="middleware" />
<DotNetWatchFile Include="$(ArtifactsDir)bin\Microsoft.Extensions.DotNetDeltaApplier\$(Configuration)\net6.0\*.dll" DeploymentSubpath="hotreload" />
<DotNetWatchFile Include="$(ArtifactsDir)bin\Microsoft.Extensions.DotNetDeltaApplier\$(Configuration)\net7.0\*.dll" DeploymentSubpath="hotreload" />
<DotNetWatchFile Include="$(ArtifactsDir)bin\DotNetWatchTasks\$(Configuration)\netstandard2.0\DotNetWatchTasks.dll" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Layout/redist/targets/OverlaySdkOnLKG.targets
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<DotNetWatchOverlay Remove="$(ArtifactsDir)bin\dotnet-watch\$(Configuration)\$(SdkTargetFramework)\Microsoft.CodeAnalysis.CSharp.dll" />
<DotNetWatchOverlay Remove="$(ArtifactsDir)bin\dotnet-watch\$(Configuration)\$(SdkTargetFramework)\Microsoft.CodeAnalysis.dll" />
<DotNetWatchOverlay Include="$(ArtifactsDir)bin\Microsoft.AspNetCore.Watch.BrowserRefresh\$(Configuration)\netcoreapp3.1\*.dll" TargetDir="middleware" />
<DotNetWatchOverlay Include="$(ArtifactsDir)bin\Microsoft.Extensions.DotNetDeltaApplier\$(Configuration)\net6.0\*.dll" TargetDir="hotreload" />
<DotNetWatchOverlay Include="$(ArtifactsDir)bin\Microsoft.Extensions.DotNetDeltaApplier\$(Configuration)\net7.0\*.dll" TargetDir="hotreload" />
<DotNetWatchOverlay Include="$(ArtifactsDir)bin\DotNetWatchTasks\$(Configuration)\netstandard2.0\DotNetWatchTasks.dll" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">net6.0</TargetFrameworks>
<TargetFrameworks>$(ResolverTargetFramework);net472</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOSPlatform(`Windows`))' == 'false' ">$(ResolverTargetFramework)</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<RuntimeIdentifiers Condition="$([MSBuild]::IsOSPlatform(`Windows`))">win-x86;win-x64</RuntimeIdentifiers>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/dotnet-watch.Tests/BrowserLaunchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task LaunchesBrowserOnStart()
await app.StartWatcherAsync();

// Verify we launched the browser.
await app.Process.GetOutputLineStartsWithAsync(expected, TimeSpan.FromMinutes(2));
await app.Process.GetOutputLineStartsWithAsync(expected);
}

[Fact]
Expand All @@ -57,7 +57,7 @@ public async Task UsesBrowserSpecifiedInEnvironment()
await app.StartWatcherAsync();

// Verify we launched the browser.
await app.Process.GetOutputLineStartsWithAsync(launchBrowserMessage, TimeSpan.FromMinutes(2));
await app.Process.GetOutputLineStartsWithAsync(launchBrowserMessage);
}
}
}
22 changes: 11 additions & 11 deletions src/Tests/dotnet-watch.Tests/DotNetWatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task RunsWithDotnetWatchEnvVariable()

await app.StartWatcherAsync();
const string messagePrefix = "DOTNET_WATCH = ";
var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));
var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix);
var envValue = message.Substring(messagePrefix.Length);
Assert.Equal("1", envValue);
}
Expand All @@ -55,16 +55,16 @@ public async Task RunsWithIterationEnvVariable()
var contents = File.ReadAllText(source);
const string messagePrefix = "DOTNET_WATCH_ITERATION = ";

var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));
var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix);
var count = int.Parse(message.Substring(messagePrefix.Length), CultureInfo.InvariantCulture);
Assert.Equal(1, count);

await app.IsWaitingForFileChange();

File.SetLastWriteTime(source, DateTime.Now);
await app.HasRestarted(TimeSpan.FromMinutes(1));
await app.HasRestarted();

message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));
message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix);
count = int.Parse(message.Substring(messagePrefix.Length), CultureInfo.InvariantCulture);
Assert.Equal(2, count);
}
Expand All @@ -90,7 +90,7 @@ public async Task RunsWithNoRestoreOnOrdinaryFileChanges()
for (var i = 0; i < 3; i++)
{
File.SetLastWriteTime(source, DateTime.Now);
var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));
var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix);

Assert.Equal(messagePrefix + " --no-restore -- wait", message.Trim());

Expand All @@ -117,7 +117,7 @@ public async Task RunsWithRestoreIfCsprojChanges()
Assert.Contains(app.Process.Output, p => string.Equals(messagePrefix + " -- wait", p.Trim()));

File.SetLastWriteTime(source, DateTime.Now);
var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));
var message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix);

// csproj changed. Do not expect a --no-restore
Assert.Equal(messagePrefix + " -- wait", message.Trim());
Expand All @@ -126,7 +126,7 @@ public async Task RunsWithRestoreIfCsprojChanges()

// regular file changed after csproj changes. Should use --no-restore
File.SetLastWriteTime(Path.Combine(app.SourceDirectory, "Program.cs"), DateTime.Now);
message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));
message = await app.Process.GetOutputLineStartsWithAsync(messagePrefix);
Assert.Equal(messagePrefix + " --no-restore -- wait", message.Trim());
}

Expand All @@ -143,7 +143,7 @@ public async Task Run_WithHotReloadEnabled_ReadsLaunchSettings()

await app.StartWatcherAsync();

await app.Process.GetOutputLineAsyncWithConsoleHistoryAsync("Environment: Development", TimeSpan.FromSeconds(10));
await app.Process.GetOutputLineAsyncWithConsoleHistoryAsync("Environment: Development");
}

[Fact(Skip = "https://github.com/dotnet/sdk/issues/24406")]
Expand All @@ -166,7 +166,7 @@ public async Task Run_WithHotReloadEnabled_ReadsLaunchSettings_WhenUsingProjectO

await app.StartWatcherAsync();

await app.Process.GetOutputLineAsyncWithConsoleHistoryAsync("Environment: Development", TimeSpan.FromSeconds(10));
await app.Process.GetOutputLineAsyncWithConsoleHistoryAsync("Environment: Development");
}

[CoreMSBuildOnlyFact]
Expand All @@ -192,8 +192,8 @@ public async Task Run_WithHotReloadEnabled_DoesNotReadConsoleIn_InNonInteractive
var standardInput = app.Process.Process.StandardInput;
var inputString = "This is a test input";

await standardInput.WriteLineAsync(inputString).WaitAsync(TimeSpan.FromSeconds(10));
await app.Process.GetOutputLineAsync($"Echo: {inputString}", TimeSpan.FromSeconds(10));
await standardInput.WriteLineAsync(inputString);
await app.Process.GetOutputLineAsync($"Echo: {inputString}");
}
}
}
37 changes: 18 additions & 19 deletions src/Tests/dotnet-watch.Tests/GlobbingAppTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace Microsoft.DotNet.Watcher.Tools
public class GlobbingAppTests
{
private const string AppName = "WatchGlobbingApp";
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(60);
private readonly TestAssetsManager _testAssetsManager;
private readonly ITestOutputHelper _logger;

Expand All @@ -38,18 +37,18 @@ public async Task ChangeCompiledFile(bool usePollingWatcher)
using var app = new WatchableApp(testAsset, _logger);

app.UsePollingWatcher = usePollingWatcher;
await app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
await app.StartWatcherAsync();

var types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);
var types = await GetCompiledAppDefinedTypes(app);
Assert.Equal(2, types);

var fileToChange = Path.Combine(app.SourceDirectory, "include", "Foo.cs");
var programCs = File.ReadAllText(fileToChange);
File.WriteAllText(fileToChange, programCs);

await app.HasFileChanged().TimeoutAfter(DefaultTimeout);
await app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);
await app.HasFileChanged();
await app.HasRestarted();
types = await GetCompiledAppDefinedTypes(app);
Assert.Equal(2, types);
}

Expand All @@ -62,16 +61,16 @@ public async Task DeleteCompiledFile()

using var app = new WatchableApp(testAsset, _logger);

await app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
await app.StartWatcherAsync();

var types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);
var types = await GetCompiledAppDefinedTypes(app);
Assert.Equal(2, types);

var fileToChange = Path.Combine(app.SourceDirectory, "include", "Foo.cs");
File.Delete(fileToChange);

await app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);
await app.HasRestarted();
types = await GetCompiledAppDefinedTypes(app);
Assert.Equal(1, types);
}

Expand All @@ -84,16 +83,16 @@ public async Task DeleteSourceFolder()

using var app = new WatchableApp(testAsset, _logger);

await app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
await app.StartWatcherAsync();

var types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);
var types = await GetCompiledAppDefinedTypes(app);
Assert.Equal(2, types);

var folderToDelete = Path.Combine(app.SourceDirectory, "include");
Directory.Delete(folderToDelete, recursive: true);

await app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await GetCompiledAppDefinedTypes(app).TimeoutAfter(DefaultTimeout);
await app.HasRestarted();
types = await GetCompiledAppDefinedTypes(app);
Assert.Equal(1, types);
}

Expand All @@ -106,13 +105,13 @@ public async Task RenameCompiledFile()

using var app = new WatchableApp(testAsset, _logger);

await app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
await app.StartWatcherAsync();

var oldFile = Path.Combine(app.SourceDirectory, "include", "Foo.cs");
var newFile = Path.Combine(app.SourceDirectory, "include", "Foo_new.cs");
File.Move(oldFile, newFile);

await app.HasRestarted().TimeoutAfter(DefaultTimeout);
await app.HasRestarted();
}

[Fact]
Expand All @@ -124,7 +123,7 @@ public async Task ChangeExcludedFile()

using var app = new WatchableApp(testAsset, _logger);

await app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
await app.StartWatcherAsync();

var changedFile = Path.Combine(app.SourceDirectory, "exclude", "Baz.cs");
File.WriteAllText(changedFile, "");
Expand All @@ -147,7 +146,7 @@ public async Task ListsFiles()
app.Start(new[] { "--list" });
var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(30));
var lines = await app.Process.GetAllOutputLinesAsync(cts.Token).TimeoutAfter(DefaultTimeout);
var lines = await app.Process.GetAllOutputLinesAsync(cts.Token);
var files = lines.Where(l => !l.StartsWith("watch :"));

AssertEx.EqualFileList(
Expand All @@ -163,7 +162,7 @@ public async Task ListsFiles()

private async Task<int> GetCompiledAppDefinedTypes(WatchableApp app)
{
var definedTypesMessage = await app.Process.GetOutputLineStartsWithAsync("Defined types = ", TimeSpan.FromSeconds(30));
var definedTypesMessage = await app.Process.GetOutputLineStartsWithAsync("Defined types = ");
return int.Parse(definedTypesMessage.Split('=').Last());
}
}
Expand Down
20 changes: 8 additions & 12 deletions src/Tests/dotnet-watch.Tests/Utilities/AwaitableProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void Start()
WriteTestOutput($"{DateTime.Now}: process started: '{_process.StartInfo.FileName} {_process.StartInfo.Arguments}'");
}

public Task<string> GetOutputLineAsyncWithConsoleHistoryAsync(string message, TimeSpan timeout)
public Task<string> GetOutputLineAsyncWithConsoleHistoryAsync(string message)
{
if (_lines.Contains(message))
{
Expand All @@ -84,23 +84,19 @@ public Task<string> GetOutputLineAsyncWithConsoleHistoryAsync(string message, Ti
}

WriteTestOutput($"Did not find [msg == '{message}'] in console history.");
return GetOutputLineAsync(message, timeout);
return GetOutputLineAsync(message);
}

public async Task<string> GetOutputLineAsync(string message, TimeSpan timeout)
public async Task<string> GetOutputLineAsync(string message)
{
WriteTestOutput($"Waiting for output line [msg == '{message}']. Will wait for {timeout.TotalSeconds} sec.");
var cts = new CancellationTokenSource();
cts.CancelAfter(timeout);
return await GetOutputLineAsync($"[msg == '{message}']", m => string.Equals(m, message, StringComparison.Ordinal), cts.Token);
WriteTestOutput($"Waiting for output line [msg == '{message}']");
return await GetOutputLineAsync($"[msg == '{message}']", m => string.Equals(m, message, StringComparison.Ordinal), CancellationToken.None);
}

public async Task<string> GetOutputLineStartsWithAsync(string message, TimeSpan timeout)
public async Task<string> GetOutputLineStartsWithAsync(string message)
{
WriteTestOutput($"Waiting for output line [msg.StartsWith('{message}')]. Will wait for {timeout.TotalSeconds} sec.");
var cts = new CancellationTokenSource();
cts.CancelAfter(timeout);
return await GetOutputLineAsync($"[msg.StartsWith('{message}')]", m => m != null && m.StartsWith(message, StringComparison.Ordinal), cts.Token);
WriteTestOutput($"Waiting for output line [msg.StartsWith('{message}')].");
return await GetOutputLineAsync($"[msg.StartsWith('{message}')]", m => m != null && m.StartsWith(message, StringComparison.Ordinal), CancellationToken.None);
}

private async Task<string> GetOutputLineAsync(string predicateName, Predicate<string> predicate, CancellationToken cancellationToken)
Expand Down
Loading