[InlineData("Release", true)]
public void PublishTemplateProject(string config, bool aot)
{
- string id = $"blazorwasm_{config}_aot_{aot}";
- InitPaths(id);
- if (Directory.Exists(_projectDir))
- Directory.Delete(_projectDir, recursive: true);
- Directory.CreateDirectory(_projectDir);
- Directory.CreateDirectory(Path.Combine(_projectDir, ".nuget"));
-
- File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "nuget6.config"), Path.Combine(_projectDir, "nuget.config"));
- File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "Blazor.Directory.Build.props"), Path.Combine(_projectDir, "Directory.Build.props"));
- File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "Blazor.Directory.Build.targets"), Path.Combine(_projectDir, "Directory.Build.targets"));
-
- string logPath = Path.Combine(s_buildEnv.LogRootPath, id);
+ string id = $"blazorwasm_{config}_aot_{aot}_{Path.GetRandomFileName()}";
+ InitBlazorWasmProjectDir(id);
new DotNetCommand(s_buildEnv, useDefaultArgs: false)
- .WithWorkingDirectory(_projectDir)
+ .WithWorkingDirectory(_projectDir!)
.ExecuteWithCapturedOutput("new blazorwasm")
.EnsureSuccessful();
- string publishLogPath = Path.Combine(logPath, $"{id}.binlog");
+ string publishLogPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}.binlog");
new DotNetCommand(s_buildEnv)
- .WithWorkingDirectory(_projectDir)
+ .WithWorkingDirectory(_projectDir!)
.ExecuteWithCapturedOutput("publish", $"-bl:{publishLogPath}", aot ? "-p:RunAOTCompilation=true" : "", $"-p:Configuration={config}")
.EnsureSuccessful();
// playwright?
}
+ [ConditionalTheory(typeof(BuildTestBase), nameof(IsNotUsingWorkloads))]
+ [InlineData("Debug")]
+ [InlineData("Release")]
+ public void NativeRef_EmitsWarningBecauseItRequiresWorkload(string config)
+ {
+ CommandResult res = PublishForRequiresWorkloadTest(config, extraItems: "<NativeFileReference Include=\"native-lib.o\" />");
+ res.EnsureSuccessful();
+
+ Assert.Contains("but the native references won't be linked in", res.Output);
+ }
+
+ [ConditionalTheory(typeof(BuildTestBase), nameof(IsNotUsingWorkloads))]
+ [InlineData("Debug")]
+ [InlineData("Release")]
+ public void AOT_FailsBecauseItRequiresWorkload(string config)
+ {
+ CommandResult res = PublishForRequiresWorkloadTest(config, extraProperties: "<RunAOTCompilation>true</RunAOTCompilation>");
+ Assert.NotEqual(0, res.ExitCode);
+ Assert.Contains("following workloads must be installed: wasm-tools", res.Output);
+ }
+
+ [ConditionalTheory(typeof(BuildTestBase), nameof(IsNotUsingWorkloads))]
+ [InlineData("Debug")]
+ [InlineData("Release")]
+ public void AOT_And_NativeRef_FailsBecauseItRequireWorkload(string config)
+ {
+ CommandResult res = PublishForRequiresWorkloadTest(config,
+ extraProperties: "<RunAOTCompilation>true</RunAOTCompilation>",
+ extraItems: "<NativeFileReference Include=\"native-lib.o\" />");
+
+ Assert.NotEqual(0, res.ExitCode);
+ Assert.Contains("following workloads must be installed: wasm-tools", res.Output);
+ }
+
+ private CommandResult PublishForRequiresWorkloadTest(string config, string extraItems="", string extraProperties="")
+ {
+ string id = $"needs_workload_{config}_{Path.GetRandomFileName()}";
+ InitBlazorWasmProjectDir(id);
+
+ new DotNetCommand(s_buildEnv, useDefaultArgs: false)
+ .WithWorkingDirectory(_projectDir!)
+ .ExecuteWithCapturedOutput("new blazorwasm")
+ .EnsureSuccessful();
+
+ if (IsNotUsingWorkloads)
+ {
+ // no packs installed, so no need to update the paths for runtime pack etc
+ File.WriteAllText(Path.Combine(_projectDir!, "Directory.Build.props"), "<Project />");
+ File.WriteAllText(Path.Combine(_projectDir!, "Directory.Build.targets"), "<Project />");
+ }
+
+ AddItemsPropertiesToProject(Path.Combine(_projectDir!, $"{id}.csproj"),
+ extraProperties: extraProperties,
+ extraItems: extraItems);
+
+ string publishLogPath = Path.Combine(s_buildEnv.LogRootPath, id, $"{id}.binlog");
+ return new DotNetCommand(s_buildEnv)
+ .WithWorkingDirectory(_projectDir!)
+ .ExecuteWithCapturedOutput("publish",
+ $"-bl:{publishLogPath}",
+ $"-p:Configuration={config}",
+ "-p:MSBuildEnableWorkloadResolver=true"); // WasmApp.LocalBuild.* disables this, but it is needed for this test
+ }
+
+ [Theory]
+ [InlineData("Debug")]
+ [InlineData("Release")]
+ public void Net50Projects_NativeReference(string config)
+ => BuildNet50Project(config, aot: false, expectError: true, @"<NativeFileReference Include=""native-lib.o"" />");
+
public static TheoryData<string, bool, bool> Net50TestData = new()
{
{ "Debug", /*aot*/ true, /*expectError*/ true },
{ "Release", /*aot*/ false, /*expectError*/ false }
};
- [ConditionalTheory(typeof(BuildTestBase), nameof(IsNotUsingWorkloads))]
+ [Theory]
[MemberData(nameof(Net50TestData))]
- public void Net50ProjectsWithNoPacksInstalled(string config, bool aot, bool expectError)
- => BuildNet50Project(config, aot, expectError);
+ public void Net50Projects_AOT(string config, bool aot, bool expectError)
+ => BuildNet50Project(config, aot: aot, expectError: expectError);
- [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
- [MemberData(nameof(Net50TestData))]
- public void Net50ProjectsWithPacksInstalled(string config, bool aot, bool expectError)
- => BuildNet50Project(config, aot, expectError);
-
- private void BuildNet50Project(string config, bool aot, bool errorExpected)
+ private void BuildNet50Project(string config, bool aot, bool expectError, string? extraItems=null)
{
- string id = $"Blazor_net50_{config}_{aot}";
- InitPaths(id);
- if (Directory.Exists(_projectDir))
- Directory.Delete(_projectDir, recursive: true);
- Directory.CreateDirectory(_projectDir);
- Directory.CreateDirectory(Path.Combine(_projectDir, ".nuget"));
+ string id = $"Blazor_net50_{config}_{aot}_{Path.GetRandomFileName()}";
+ InitBlazorWasmProjectDir(id);
string directoryBuildTargets = @"<Project>
<Target Name=""PrintAllProjects"" BeforeTargets=""Build"">
</Target>
</Project>";
- File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "nuget6.config"), Path.Combine(_projectDir, "nuget.config"));
- File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.props"), "<Project />");
- File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.targets"), directoryBuildTargets);
+ File.WriteAllText(Path.Combine(_projectDir!, "Directory.Build.props"), "<Project />");
+ File.WriteAllText(Path.Combine(_projectDir!, "Directory.Build.targets"), directoryBuildTargets);
string logPath = Path.Combine(s_buildEnv.LogRootPath, id);
Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, "Blazor_net50"), Path.Combine(_projectDir!));
+ string projectFile = Path.Combine(_projectDir!, "Blazor_net50.csproj");
+ AddItemsPropertiesToProject(projectFile, extraItems: extraItems);
+
string publishLogPath = Path.Combine(logPath, $"{id}.binlog");
CommandResult result = new DotNetCommand(s_buildEnv)
- .WithWorkingDirectory(_projectDir)
- .ExecuteWithCapturedOutput("publish",
- $"-bl:{publishLogPath}",
- (aot ? "-p:RunAOTCompilation=true" : ""),
- $"-p:Configuration={config}");
+ .WithWorkingDirectory(_projectDir!)
+ .ExecuteWithCapturedOutput("publish",
+ $"-bl:{publishLogPath}",
+ (aot ? "-p:RunAOTCompilation=true" : ""),
+ $"-p:Configuration={config}");
- if (errorExpected)
+ if (expectError)
{
result.EnsureExitCode(1);
- Assert.Contains("** UsingBrowserRuntimeWorkload: 'false'", result.Output);
- Assert.Contains("error : WebAssembly workloads (required for AOT) are only supported for projects targeting net6.0+", result.Output);
+ Assert.Contains("are only supported for projects targeting net6.0+", result.Output);
}
else
{