2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// Copyright (c) .NET Foundation and contributors. All rights reserved. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								using  System ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								using  System.IO ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-26 12:17:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								using  System.Diagnostics ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								using  System.Runtime.InteropServices ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								using  FluentAssertions ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								using  Microsoft.DotNet.Cli.Utils ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								using  Microsoft.DotNet.PlatformAbstractions ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								using  Microsoft.DotNet.Tools.Test.Utilities ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								using  Xunit ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								namespace  Microsoft.DotNet.Cli.Publish.Tests 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    public  class  GivenDotnetPublishPublishesProjects  :  TestBase 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        [Fact] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        public  void  ItPublishesARunnablePortableApp ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  testAppName  =  "MSBuildTestApp" ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-15 15:35:03 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  testInstance  =  TestAssets . Get ( testAppName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            . CreateInstance ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                            . WithSourceFiles ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-15 15:35:03 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  testProjectDirectory  =  testInstance . Root . FullName ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            new  RestoreCommand ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:41:06 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . WithWorkingDirectory ( testProjectDirectory ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Execute ( "/p:SkipInvalidConfigurations=true" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 22:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Should ( ) . Pass ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-27 14:41:06 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            new  PublishCommand ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                . WithWorkingDirectory ( testProjectDirectory ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-02 12:46:21 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Execute ( "--framework netcoreapp2.0" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 22:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Should ( ) . Pass ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  configuration  =  Environment . GetEnvironmentVariable ( "CONFIGURATION" )  ? ?  "Debug" ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-02 12:46:21 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  outputDll  =  Path . Combine ( testProjectDirectory ,  "bin" ,  configuration ,  "netcoreapp2.0" ,  "publish" ,  $"{testAppName}.dll" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-16 01:31:16 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            new  DotnetCommand ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								                . ExecuteWithCapturedOutput ( outputDll ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 22:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Should ( ) . Pass ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                         . And . HaveStdOutContaining ( "Hello World" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        [Fact] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        public  void  ItPublishesARunnableSelfContainedApp ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-03 09:37:15 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  testAppName  =  "MSBuildTestApp" ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  testInstance  =  TestAssets . Get ( testAppName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . CreateInstance ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . WithSourceFiles ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . WithRestoreFiles ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  testProjectDirectory  =  testInstance . Root ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  rid  =  DotnetLegacyRuntimeIdentifiers . InferLegacyRestoreRuntimeIdentifier ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 22:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            new  PublishCommand ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-02 12:46:21 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . WithFramework ( "netcoreapp2.0" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . WithRuntime ( rid ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . WithWorkingDirectory ( testProjectDirectory ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                //Workaround for https://github.com/dotnet/cli/issues/4501 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . WithEnvironmentVariable ( "SkipInvalidConfigurations" ,  "true" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . Execute ( "/p:SkipInvalidConfigurations=true" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 22:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Should ( ) . Pass ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  configuration  =  Environment . GetEnvironmentVariable ( "CONFIGURATION" )  ? ?  "Debug" ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  outputProgram  =  testProjectDirectory 
							 
						 
					
						
							
								
									
										
										
										
											2017-03-02 12:46:21 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . GetDirectory ( "bin" ,  configuration ,  "netcoreapp2.0" ,  rid ,  "publish" ,  $"{testAppName}{Constants.ExeSuffix}" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . FullName ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-26 12:17:21 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            if  ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                //Workaround for https://github.com/dotnet/corefx/issues/15516 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                Process . Start ( "chmod" ,  $"u+x {outputProgram}" ) . WaitForExit ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            new  TestCommand ( outputProgram ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . ExecuteWithCapturedOutput ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-26 22:23:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Should ( ) . Pass ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-10-27 18:46:43 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                     . And . HaveStdOutContaining ( "Hello World" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-30 17:47:23 -05:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-18 00:45:25 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        [Fact] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        public  void  ItPublishesAppWhenRestoringToSpecificPackageDirectory ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-15 15:35:03 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  rootPath  =  TestAssets . CreateTestDirectory ( ) . FullName ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-18 00:45:25 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            var  rootDir  =  new  DirectoryInfo ( rootPath ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            string  dir  =  "pkgs" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            string  args  =  $"--packages {dir}" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-03-02 12:46:21 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            string  newArgs  =  $"console -o \" { rootPath } \ "" ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-31 17:31:37 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            new  NewCommandShim ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-18 00:45:25 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . WithWorkingDirectory ( rootPath ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-31 17:31:37 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Execute ( newArgs ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-18 00:45:25 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . Should ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . Pass ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            new  RestoreCommand ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . WithWorkingDirectory ( rootPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . Execute ( args ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . Should ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . Pass ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            new  PublishCommand ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . WithWorkingDirectory ( rootPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . ExecuteWithCapturedOutput ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . Should ( ) . Pass ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  configuration  =  Environment . GetEnvironmentVariable ( "CONFIGURATION" )  ? ?  "Debug" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            var  outputProgram  =  rootDir 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-27 17:46:55 -06:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . GetDirectory ( "bin" ,  configuration ,  "netcoreapp2.0" ,  "publish" ,  $"{rootDir.Name}.dll" ) 
							 
						 
					
						
							
								
									
										
										
										
											2016-12-18 00:45:25 -08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								                . FullName ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            new  TestCommand ( outputProgram ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . ExecuteWithCapturedOutput ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                . Should ( ) . Pass ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								                     . And . HaveStdOutContaining ( "Hello World" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2016-09-23 11:11:44 -05:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}