@@ -78,6 +78,41 @@ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_enabled(string
7878 }
7979 }
8080
81+ [ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
82+ [ InlineData ( ToolsetInfo . CurrentTargetFramework ) ]
83+ public void NativeAot_hw_runs_with_no_warnings_when_PublishAot_is_false ( string targetFramework )
84+ {
85+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) || RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
86+ {
87+ var projectName = "HellowWorldNativeAotApp" ;
88+ var rid = EnvironmentInfo . GetCompatibleRid ( targetFramework ) ;
89+
90+ var testProject = CreateHelloWorldTestProject ( targetFramework , projectName , true ) ;
91+ testProject . AdditionalProperties [ "PublishAot" ] = "false" ;
92+ var testAsset = _testAssetsManager . CreateTestProject ( testProject ) ;
93+
94+ var publishCommand = new PublishCommand ( Log , Path . Combine ( testAsset . TestRoot , testProject . Name ) ) ;
95+ publishCommand
96+ . Execute ( $ "/p:RuntimeIdentifier={ rid } ")
97+ . Should ( ) . Pass ( )
98+ . And . NotHaveStdOutContaining ( "IL2026" )
99+ . And . NotHaveStdErrContaining ( "NETSDK1179" )
100+ . And . NotHaveStdErrContaining ( "warning" ) ;
101+
102+ var publishDirectory = publishCommand . GetOutputDirectory ( targetFramework : targetFramework , runtimeIdentifier : rid ) . FullName ;
103+ var sharedLibSuffix = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? ".dll" : ".so" ;
104+ var publishedDll = Path . Combine ( publishDirectory , $ "{ projectName } { sharedLibSuffix } ") ;
105+ var publishedExe = Path . Combine ( publishDirectory , $ "{ testProject . Name } { Constants . ExeSuffix } ") ;
106+
107+ // PublishAot=false will be a normal publish
108+ File . Exists ( publishedDll ) . Should ( ) . BeTrue ( ) ;
109+
110+ var command = new RunExeCommand ( Log , publishedExe )
111+ . Execute ( ) . Should ( ) . Pass ( )
112+ . And . HaveStdOutContaining ( "Hello World" ) ;
113+ }
114+ }
115+
81116 [ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
82117 [ InlineData ( ToolsetInfo . CurrentTargetFramework ) ]
83118 public void NativeAot_app_runs_in_debug_with_no_config_when_PublishAot_is_enabled ( string targetFramework )
@@ -274,6 +309,103 @@ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_enabled(string
274309 }
275310 }
276311
312+ [ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
313+ [ InlineData ( ToolsetInfo . CurrentTargetFramework ) ]
314+ public void NativeAot_hw_runs_with_PackageReference_PublishAot_is_empty ( string targetFramework )
315+ {
316+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) || RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
317+ {
318+ var projectName = "HellowWorldNativeAotApp" ;
319+ var rid = EnvironmentInfo . GetCompatibleRid ( targetFramework ) ;
320+
321+ var testProject = CreateHelloWorldTestProject ( targetFramework , projectName , true ) ;
322+
323+ // This will add a reference to a package that will also be automatically imported by the SDK
324+ testProject . PackageReferences . Add ( new TestPackageReference ( "Microsoft.DotNet.ILCompiler" , "7.0.0-*" ) ) ;
325+
326+ // Linux symbol files are embedded and require additional steps to be stripped to a separate file
327+ // assumes /bin (or /usr/bin) are in the PATH
328+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
329+ {
330+ testProject . AdditionalProperties [ "StripSymbols" ] = "true" ;
331+ testProject . AdditionalProperties [ "ObjCopyName" ] = "objcopy" ;
332+ }
333+ var testAsset = _testAssetsManager . CreateTestProject ( testProject ) ;
334+
335+ var publishCommand = new PublishCommand ( Log , Path . Combine ( testAsset . TestRoot , testProject . Name ) ) ;
336+ publishCommand
337+ . Execute ( $ "/p:RuntimeIdentifier={ rid } ")
338+ . Should ( ) . Pass ( ) ;
339+
340+ var publishDirectory = publishCommand . GetOutputDirectory ( targetFramework : targetFramework , runtimeIdentifier : rid ) . FullName ;
341+ var sharedLibSuffix = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? ".dll" : ".so" ;
342+ var publishedDll = Path . Combine ( publishDirectory , $ "{ projectName } { sharedLibSuffix } ") ;
343+ var publishedExe = Path . Combine ( publishDirectory , $ "{ testProject . Name } { Constants . ExeSuffix } ") ;
344+ var symbolSuffix = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? ".pdb" : ".dbg" ;
345+ var publishedDebugFile = Path . Combine ( publishDirectory , $ "{ testProject . Name } { symbolSuffix } ") ;
346+
347+ // NativeAOT published dir should not contain a non-host stand alone package
348+ File . Exists ( publishedDll ) . Should ( ) . BeFalse ( ) ;
349+ // The exe exist and should be native
350+ File . Exists ( publishedExe ) . Should ( ) . BeTrue ( ) ;
351+ File . Exists ( publishedDebugFile ) . Should ( ) . BeTrue ( ) ;
352+ IsNativeImage ( publishedExe ) . Should ( ) . BeTrue ( ) ;
353+
354+ var command = new RunExeCommand ( Log , publishedExe )
355+ . Execute ( ) . Should ( ) . Pass ( )
356+ . And . HaveStdOutContaining ( "Hello World" ) ;
357+ }
358+ }
359+
360+ [ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
361+ [ InlineData ( ToolsetInfo . CurrentTargetFramework ) ]
362+ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_enabled ( string targetFramework )
363+ {
364+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && ( RuntimeInformation . OSArchitecture == System . Runtime . InteropServices . Architecture . X64 ) )
365+ {
366+ var projectName = "HellowWorldNativeAotApp" ;
367+ var rid = "win-arm64" ;
368+
369+ var testProject = CreateHelloWorldTestProject ( targetFramework , projectName , true ) ;
370+ testProject . AdditionalProperties [ "PublishAot" ] = "true" ;
371+
372+ // This will add a reference to a package that will also be automatically imported by the SDK
373+ testProject . PackageReferences . Add ( new TestPackageReference ( "Microsoft.DotNet.ILCompiler" , "7.0.0-*" ) ) ;
374+ testProject . PackageReferences . Add ( new TestPackageReference ( "runtime.win-x64.Microsoft.DotNet.ILCompiler" , "7.0.0-*" ) ) ;
375+
376+ var testAsset = _testAssetsManager . CreateTestProject ( testProject ) ;
377+
378+ var publishCommand = new PublishCommand ( Log , Path . Combine ( testAsset . TestRoot , testProject . Name ) ) ;
379+ publishCommand
380+ . Execute ( $ "/p:RuntimeIdentifier={ rid } ")
381+ . Should ( ) . Pass ( ) ;
382+ }
383+ }
384+
385+ [ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
386+ [ InlineData ( ToolsetInfo . CurrentTargetFramework ) ]
387+ public void NativeAot_hw_runs_with_cross_PackageReference_PublishAot_is_empty ( string targetFramework )
388+ {
389+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && ( RuntimeInformation . OSArchitecture == System . Runtime . InteropServices . Architecture . X64 ) )
390+ {
391+ var projectName = "HellowWorldNativeAotApp" ;
392+ var rid = "win-arm64" ;
393+
394+ var testProject = CreateHelloWorldTestProject ( targetFramework , projectName , true ) ;
395+
396+ // This will add a reference to a package that will also be automatically imported by the SDK
397+ testProject . PackageReferences . Add ( new TestPackageReference ( "Microsoft.DotNet.ILCompiler" , "7.0.0-*" ) ) ;
398+ testProject . PackageReferences . Add ( new TestPackageReference ( "runtime.win-x64.Microsoft.DotNet.ILCompiler" , "7.0.0-*" ) ) ;
399+
400+ var testAsset = _testAssetsManager . CreateTestProject ( testProject ) ;
401+
402+ var publishCommand = new PublishCommand ( Log , Path . Combine ( testAsset . TestRoot , testProject . Name ) ) ;
403+ publishCommand
404+ . Execute ( $ "/p:RuntimeIdentifier={ rid } ")
405+ . Should ( ) . Pass ( ) ;
406+ }
407+ }
408+
277409 [ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
278410 [ InlineData ( ToolsetInfo . CurrentTargetFramework ) ]
279411 public void Only_Aot_warnings_are_produced_if_EnableAotAnalyzer_is_set ( string targetFramework )
0 commit comments