diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs
index c8cca6cd0774e..555cfa73fad17 100644
--- a/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs
+++ b/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs
@@ -136,5 +136,36 @@ public static int Main()
string cryptoInitMsg = "MONO_WASM: Initializing Crypto WebWorker";
Assert.DoesNotContain(cryptoInitMsg, output);
}
+
+ [Theory]
+ [BuildAndRun(aot: false)]
+ [BuildAndRun(aot: true)]
+ public void ProjectWithNativeLibrary(BuildArgs buildArgs, RunHost host, string id)
+ {
+ string projectName = $"AppUsingNativeLibrary-a";
+ buildArgs = buildArgs with { ProjectName = projectName };
+ buildArgs = ExpandBuildArgs(buildArgs, extraItems: "\n");
+
+ if (!_buildContext.TryGetBuildFor(buildArgs, out BuildProduct? _))
+ {
+ InitPaths(id);
+ if (Directory.Exists(_projectDir))
+ Directory.Delete(_projectDir, recursive: true);
+
+ Utils.DirectoryCopy(Path.Combine(BuildEnvironment.TestAssetsPath, "AppUsingNativeLib"), _projectDir);
+ File.Copy(Path.Combine(BuildEnvironment.TestAssetsPath, "native-libs", "native-lib.o"), Path.Combine(_projectDir, "native-lib.o"));
+ }
+
+ BuildProject(buildArgs,
+ id: id,
+ new BuildProjectOptions(DotnetWasmFromRuntimePack: false));
+
+ string output = RunAndTestWasmApp(buildArgs, buildDir: _projectDir, expectedExitCode: 0,
+ test: output => {},
+ host: host, id: id);
+
+ Assert.Contains("print_line: 100", output);
+ Assert.Contains("from pinvoke: 142", output);
+ }
}
}
diff --git a/src/mono/wasm/build/WasmApp.Common.targets b/src/mono/wasm/build/WasmApp.Common.targets
index f06b9a1261fe5..e3c4ef2b934dc 100644
--- a/src/mono/wasm/build/WasmApp.Common.targets
+++ b/src/mono/wasm/build/WasmApp.Common.targets
@@ -295,6 +295,11 @@
<_WasmShouldAOT Condition="'$(_WasmShouldAOT)' == ''">false
+
+ <_ExistingNativeLibrary Include="@(NativeLibrary->Exists())" />
+
+
+