@@ -500,6 +500,141 @@ static XElement GetToolSettingsFile(string packagePath)
500500
501501 }
502502
503+ [ Fact ]
504+ public void InstallToolWithHigherFrameworkAsGlobalToolShowsAppropriateError ( )
505+ {
506+ var toolPackagesPath = CreateNet99ToolPackage ( ) ;
507+ var testDirectory = _testAssetsManager . CreateTestDirectory ( ) ;
508+ var homeFolder = Path . Combine ( testDirectory . Path , "home" ) ;
509+
510+ var result = new DotnetToolCommand ( Log , "install" , "-g" , "Net99Tool" , "--add-source" , toolPackagesPath )
511+ . WithEnvironmentVariables ( homeFolder )
512+ . WithWorkingDirectory ( testDirectory . Path )
513+ . Execute ( ) ;
514+
515+ result . Should ( ) . Fail ( )
516+ . And . HaveStdErrContaining ( "requires a higher version of .NET" )
517+ . And . HaveStdErrContaining ( ".NET 99" ) ;
518+ }
519+
520+ [ Fact ]
521+ public void InstallToolWithHigherFrameworkAsLocalToolShowsAppropriateError ( )
522+ {
523+ var toolPackagesPath = CreateNet99ToolPackage ( ) ;
524+ var testDirectory = _testAssetsManager . CreateTestDirectory ( ) ;
525+ var homeFolder = Path . Combine ( testDirectory . Path , "home" ) ;
526+
527+ new DotnetCommand ( Log , "new" , "tool-manifest" )
528+ . WithEnvironmentVariables ( homeFolder )
529+ . WithWorkingDirectory ( testDirectory . Path )
530+ . Execute ( )
531+ . Should ( ) . Pass ( ) ;
532+
533+ var result = new DotnetToolCommand ( Log , "install" , "Net99Tool" , "--add-source" , toolPackagesPath )
534+ . WithEnvironmentVariables ( homeFolder )
535+ . WithWorkingDirectory ( testDirectory . Path )
536+ . Execute ( ) ;
537+
538+ result . Should ( ) . Fail ( )
539+ . And . HaveStdErrContaining ( "requires a higher version of .NET" )
540+ . And . HaveStdErrContaining ( ".NET 99" ) ;
541+ }
542+
543+ [ Fact ]
544+ public void RunToolWithHigherFrameworkUsingDnxShowsAppropriateError ( )
545+ {
546+ var toolPackagesPath = CreateNet99ToolPackage ( ) ;
547+ var testDirectory = _testAssetsManager . CreateTestDirectory ( ) ;
548+ var homeFolder = Path . Combine ( testDirectory . Path , "home" ) ;
549+
550+ var result = new DotnetToolCommand ( Log , "exec" , "Net99Tool" , "--yes" , "--source" , toolPackagesPath )
551+ . WithEnvironmentVariables ( homeFolder )
552+ . WithWorkingDirectory ( testDirectory . Path )
553+ . Execute ( ) ;
554+
555+ result . Should ( ) . Fail ( )
556+ . And . HaveStdErrContaining ( "requires a higher version of .NET" )
557+ . And . HaveStdErrContaining ( ".NET 99" ) ;
558+ }
559+
560+ /// <summary>
561+ /// Creates a tool package that targets net99.0 to simulate a tool requiring a higher .NET version
562+ /// </summary>
563+ private string CreateNet99ToolPackage ( )
564+ {
565+ var testDirectory = _testAssetsManager . CreateTestDirectory ( identifier : "net99tool" ) ;
566+ var packageOutputPath = Path . Combine ( testDirectory . Path , "packages" ) ;
567+ Directory . CreateDirectory ( packageOutputPath ) ;
568+
569+ // Create a minimal .nupkg with net99.0 framework
570+ var nupkgPath = Path . Combine ( packageOutputPath , "Net99Tool.1.0.0.nupkg" ) ;
571+
572+ using ( var archive = ZipFile . Open ( nupkgPath , ZipArchiveMode . Create ) )
573+ {
574+ // Add nuspec file
575+ var nuspecEntry = archive . CreateEntry ( "Net99Tool.nuspec" ) ;
576+ using ( var writer = new StreamWriter ( nuspecEntry . Open ( ) ) )
577+ {
578+ writer . Write ( @"<?xml version=""1.0"" encoding=""utf-8""?>
579+ <package xmlns=""http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"">
580+ <metadata>
581+ <id>Net99Tool</id>
582+ <version>1.0.0</version>
583+ <authors>Test</authors>
584+ <description>Test tool targeting net99.0</description>
585+ <packageTypes>
586+ <packageType name=""DotnetTool"" />
587+ </packageTypes>
588+ </metadata>
589+ </package>" ) ;
590+ }
591+
592+ // Add DotnetToolSettings.xml
593+ var settingsEntry = archive . CreateEntry ( "tools/net99.0/any/DotnetToolSettings.xml" ) ;
594+ using ( var writer = new StreamWriter ( settingsEntry . Open ( ) ) )
595+ {
596+ writer . Write ( @"<?xml version=""1.0"" encoding=""utf-8""?>
597+ <DotNetCliTool Version=""1"">
598+ <Commands>
599+ <Command Name=""net99tool"" EntryPoint=""Net99Tool.dll"" Runner=""dotnet"" />
600+ </Commands>
601+ </DotNetCliTool>" ) ;
602+ }
603+
604+ // Add a minimal DLL (just empty file for this test)
605+ var dllEntry = archive . CreateEntry ( "tools/net99.0/any/Net99Tool.dll" ) ;
606+ using ( var writer = new StreamWriter ( dllEntry . Open ( ) ) )
607+ {
608+ writer . Write ( "" ) ;
609+ }
610+
611+ // Add .rels file
612+ var relsEntry = archive . CreateEntry ( "_rels/.rels" ) ;
613+ using ( var writer = new StreamWriter ( relsEntry . Open ( ) ) )
614+ {
615+ writer . Write ( @"<?xml version=""1.0"" encoding=""utf-8""?>
616+ <Relationships xmlns=""http://schemas.openxmlformats.org/package/2006/relationships"">
617+ <Relationship Type=""http://schemas.microsoft.com/packaging/2010/07/manifest"" Target=""/Net99Tool.nuspec"" Id=""Re0"" />
618+ </Relationships>" ) ;
619+ }
620+
621+ // Add [Content_Types].xml
622+ var contentTypesEntry = archive . CreateEntry ( "[Content_Types].xml" ) ;
623+ using ( var writer = new StreamWriter ( contentTypesEntry . Open ( ) ) )
624+ {
625+ writer . Write ( @"<?xml version=""1.0"" encoding=""utf-8""?>
626+ <Types xmlns=""http://schemas.openxmlformats.org/package/2006/content-types"">
627+ <Default Extension=""rels"" ContentType=""application/vnd.openxmlformats-package.relationships+xml"" />
628+ <Default Extension=""nuspec"" ContentType=""application/octet-stream"" />
629+ <Default Extension=""xml"" ContentType=""application/xml"" />
630+ <Default Extension=""dll"" ContentType=""application/octet-stream"" />
631+ </Types>" ) ;
632+ }
633+ }
634+
635+ return packageOutputPath ;
636+ }
637+
503638 /// <summary>
504639 /// Opens the nupkg and verifies that it does not contain a dependency on the given dll.
505640 /// </summary>
0 commit comments