@@ -563,19 +563,27 @@ public void RunToolWithHigherFrameworkUsingDnxShowsAppropriateError()
563563 private string CreateNet99ToolPackage ( )
564564 {
565565 var testDirectory = _testAssetsManager . CreateTestDirectory ( identifier : "net99tool" ) ;
566- var packageOutputPath = Path . Combine ( testDirectory . Path , "packages " ) ;
567- Directory . CreateDirectory ( packageOutputPath ) ;
566+ var projectDirectory = Path . Combine ( testDirectory . Path , "toolproject " ) ;
567+ Directory . CreateDirectory ( projectDirectory ) ;
568568
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""?>
569+ // Create the directory structure for the tool files
570+ var toolsDir = Path . Combine ( projectDirectory , "tools" , "net99.0" , "any" ) ;
571+ Directory . CreateDirectory ( toolsDir ) ;
572+
573+ // Create DotnetToolSettings.xml
574+ File . WriteAllText ( Path . Combine ( toolsDir , "DotnetToolSettings.xml" ) , @"<?xml version=""1.0"" encoding=""utf-8""?>
575+ <DotNetCliTool Version=""1"">
576+ <Commands>
577+ <Command Name=""net99tool"" EntryPoint=""Net99Tool.dll"" Runner=""dotnet"" />
578+ </Commands>
579+ </DotNetCliTool>" ) ;
580+
581+ // Create a minimal DLL file
582+ File . WriteAllText ( Path . Combine ( toolsDir , "Net99Tool.dll" ) , "" ) ;
583+
584+ // Create a .nuspec file
585+ var nuspecPath = Path . Combine ( projectDirectory , "Net99Tool.nuspec" ) ;
586+ File . WriteAllText ( nuspecPath , @"<?xml version=""1.0"" encoding=""utf-8""?>
579587<package xmlns=""http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"">
580588 <metadata>
581589 <id>Net99Tool</id>
@@ -586,51 +594,19 @@ private string CreateNet99ToolPackage()
586594 <packageType name=""DotnetTool"" />
587595 </packageTypes>
588596 </metadata>
597+ <files>
598+ <file src=""tools\**"" target=""tools"" />
599+ </files>
589600</package>" ) ;
590- }
591601
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- }
602+ // Use NuGet pack to create the package
603+ var packageOutputPath = Path . Combine ( testDirectory . Path , "packages" ) ;
604+ Directory . CreateDirectory ( packageOutputPath ) ;
605+
606+ new DotnetCommand ( Log , "pack" , nuspecPath , "-o" , packageOutputPath )
607+ . WithWorkingDirectory ( projectDirectory )
608+ . Execute ( )
609+ . Should ( ) . Pass ( ) ;
634610
635611 return packageOutputPath ;
636612 }
@@ -651,9 +627,11 @@ static class EndToEndToolTestExtensions
651627 {
652628 public static TestCommand WithEnvironmentVariables ( this TestCommand command , string homeFolder )
653629 {
630+ var nugetPackagesFolder = Path . Combine ( homeFolder , ".nuget" , "packages" ) ;
654631 return command . WithEnvironmentVariable ( "DOTNET_CLI_HOME" , homeFolder )
655632 . WithEnvironmentVariable ( "DOTNET_NOLOGO" , "1" )
656- . WithEnvironmentVariable ( "DOTNET_ADD_GLOBAL_TOOLS_TO_PATH" , "0" ) ;
633+ . WithEnvironmentVariable ( "DOTNET_ADD_GLOBAL_TOOLS_TO_PATH" , "0" )
634+ . WithEnvironmentVariable ( "NUGET_PACKAGES" , nugetPackagesFolder ) ;
657635 }
658636 }
659637}
0 commit comments