/// <inheritdoc/> public string GetInstallerScriptSnippet( BuildScriptGeneratorContext context, PlatformDetectorResult detectorResult) { var versionMap = _versionProvider.GetSupportedVersions(); string installationScriptSnippet = null; if (_commonOptions.EnableDynamicInstall) { _logger.LogDebug("Dynamic install is enabled."); string globalJsonSdkVersion; var availableSdks = versionMap.Values; globalJsonSdkVersion = _globalJsonSdkResolver.GetSatisfyingSdkVersion( context.SourceRepo, detectorResult.PlatformVersion, availableSdks); if (_platformInstaller.IsVersionAlreadyInstalled( detectorResult.PlatformVersion, globalJsonSdkVersion)) { _logger.LogDebug( "DotNetCore runtime version {runtimeVersion} is already installed. " + "So skipping installing it again.", detectorResult.PlatformVersion); } else { _logger.LogDebug( "DotNetCore runtime version {runtimeVersion} is not installed. " + "So generating an installation script snippet for it.", detectorResult.PlatformVersion); installationScriptSnippet = _platformInstaller.GetInstallerScriptSnippet( detectorResult.PlatformVersion, globalJsonSdkVersion); } } else { _logger.LogDebug("Dynamic install is not enabled."); } return(installationScriptSnippet); }
/// <inheritdoc/> public string GetInstallerScriptSnippet( BuildScriptGeneratorContext context, PlatformDetectorResult detectorResult) { var dotNetCorePlatformDetectorResult = detectorResult as DotNetCorePlatformDetectorResult; if (dotNetCorePlatformDetectorResult == null) { throw new ArgumentException( $"Expected '{nameof(detectorResult)}' argument to be of type " + $"'{typeof(DotNetCorePlatformDetectorResult)}' but got '{detectorResult.GetType()}'."); } string installationScriptSnippet = null; if (_commonOptions.EnableDynamicInstall) { _logger.LogDebug("Dynamic install is enabled."); if (_platformInstaller.IsVersionAlreadyInstalled(dotNetCorePlatformDetectorResult.SdkVersion)) { _logger.LogDebug( "DotNetCore SDK version {globalJsonSdkVersion} is already installed. " + "So skipping installing it again.", dotNetCorePlatformDetectorResult.SdkVersion); } else { _logger.LogDebug( "DotNetCore SDK version {globalJsonSdkVersion} is not installed. " + "So generating an installation script snippet for it.", dotNetCorePlatformDetectorResult.SdkVersion); installationScriptSnippet = _platformInstaller.GetInstallerScriptSnippet( dotNetCorePlatformDetectorResult.SdkVersion); } } else { _logger.LogDebug("Dynamic install is not enabled."); } return(installationScriptSnippet); }
/// <inheritdoc/> public BuildScriptSnippet GenerateBashBuildScriptSnippet(BuildScriptGeneratorContext context) { var versionMap = _versionProvider.GetSupportedVersions(); string installationScriptSnippet = null; string globalJsonSdkVersion = null; if (_cliOptions.EnableDynamicInstall) { _logger.LogDebug("Dynamic install is enabled."); var availableSdks = versionMap.Values; globalJsonSdkVersion = _globalJsonSdkResolver.GetSatisfyingSdkVersion( context.SourceRepo, context.ResolvedDotNetCoreRuntimeVersion, availableSdks); if (_platformInstaller.IsVersionAlreadyInstalled( context.ResolvedDotNetCoreRuntimeVersion, globalJsonSdkVersion)) { _logger.LogDebug( "DotNetCore runtime version {runtimeVersion} is already installed. " + "So skipping installing it again.", context.ResolvedDotNetCoreRuntimeVersion); } else { _logger.LogDebug( "DotNetCore runtime version {runtimeVersion} is not installed. " + "So generating an installation script snippet for it.", context.ResolvedDotNetCoreRuntimeVersion); installationScriptSnippet = _platformInstaller.GetInstallerScriptSnippet( context.ResolvedDotNetCoreRuntimeVersion, globalJsonSdkVersion); } } else { _logger.LogDebug("Dynamic install is not enabled."); } var manifestFileProperties = new Dictionary <string, string>(); manifestFileProperties[ManifestFilePropertyKeys.OperationId] = context.OperationId; manifestFileProperties[ManifestFilePropertyKeys.DotNetCoreRuntimeVersion] = context.ResolvedDotNetCoreRuntimeVersion; if (string.IsNullOrEmpty(globalJsonSdkVersion)) { manifestFileProperties[ManifestFilePropertyKeys.DotNetCoreSdkVersion] = versionMap[context.ResolvedDotNetCoreRuntimeVersion]; } else { manifestFileProperties[ManifestFilePropertyKeys.DotNetCoreSdkVersion] = globalJsonSdkVersion; } var projectFile = _projectFileProvider.GetRelativePathToProjectFile(context); if (string.IsNullOrEmpty(projectFile)) { return(null); } (var preBuildCommand, var postBuildCommand) = PreAndPostBuildCommandHelper.GetPreAndPostBuildCommands( context.SourceRepo, _cliOptions); var sourceDir = _cliOptions.SourceDir; var temporaryDestinationDir = "/tmp/puboutput"; var destinationDir = _cliOptions.DestinationDir; var intermediateDir = _cliOptions.IntermediateDir; var hasUserSuppliedDestinationDir = !string.IsNullOrEmpty(_cliOptions.DestinationDir); var buildConfiguration = GetBuildConfiguration(); // Since destination directory is optional for .NET Core builds, check var outputIsSubDirOfSourceDir = false; if (!string.IsNullOrEmpty(_cliOptions.DestinationDir)) { outputIsSubDirOfSourceDir = DirectoryHelper.IsSubDirectory( _cliOptions.DestinationDir, _cliOptions.SourceDir); } var scriptBuilder = new StringBuilder(); scriptBuilder .AppendLine("#!/bin/bash") .AppendLine("set -e") .AppendLine(); // For 1st build this is not a problem, but for subsequent builds we want the source directory to be // in a clean state to avoid considering earlier build's state and potentially yielding incorrect results. if (outputIsSubDirOfSourceDir) { scriptBuilder.AppendLine($"rm -rf {_cliOptions.DestinationDir}"); } scriptBuilder.AddScriptToCopyToIntermediateDirectory( sourceDir: ref sourceDir, intermediateDir: intermediateDir, GetDirectoriesToExcludeFromCopyToIntermediateDir(context)) .AppendFormatWithLine("cd \"{0}\"", sourceDir) .AppendLine(); if (!string.IsNullOrEmpty(installationScriptSnippet)) { scriptBuilder.AppendLine(installationScriptSnippet); } scriptBuilder.AddScriptToCopyToIntermediateDirectory( sourceDir: ref sourceDir, intermediateDir: intermediateDir, GetDirectoriesToExcludeFromCopyToIntermediateDir(context)) .AppendFormatWithLine("cd \"{0}\"", sourceDir) .AppendLine(); scriptBuilder .AddScriptToSetupSourceAndDestinationDirectories( sourceDir: sourceDir, temporaryDestinationDir: temporaryDestinationDir, destinationDir: destinationDir, hasUserSuppliedDestinationDir: hasUserSuppliedDestinationDir) .AppendBenvCommand($"dotnet={context.ResolvedDotNetCoreRuntimeVersion}") .AddScriptToRunPreBuildCommand(sourceDir: sourceDir, preBuildCommand: preBuildCommand) .AppendLine("echo") .AppendLine("dotnetCoreVersion=$(dotnet --version)") .AppendLine("echo \"Using .NET Core SDK Version: $dotnetCoreVersion\"") .AppendLine() .AddScriptToRestorePackages(projectFile); if (hasUserSuppliedDestinationDir) { scriptBuilder .AddScriptToPublishOutput( projectFile: projectFile, buildConfiguration: buildConfiguration, finalDestinationDir: destinationDir) .AddScriptToRunPostBuildCommand( sourceDir: sourceDir, postBuildCommand: postBuildCommand); } else { scriptBuilder .AddScriptToBuildProject(projectFile) .AddScriptToRunPostBuildCommand( sourceDir: sourceDir, postBuildCommand: postBuildCommand); } SetStartupFileNameInfoInManifestFile(context, projectFile, manifestFileProperties); scriptBuilder .AddScriptToCreateManifestFile( manifestFileProperties, manifestDir: _cliOptions.ManifestDir, finalDestinationDir: destinationDir) .AppendLine("echo Done."); return(new BuildScriptSnippet { BashBuildScriptSnippet = scriptBuilder.ToString(), IsFullScript = true, }); }
/// <inheritdoc/> public BuildScriptSnippet GenerateBashBuildScriptSnippet(BuildScriptGeneratorContext context) { var versionMap = _versionProvider.GetSupportedVersions(); string installationScriptSnippet = null; string globalJsonSdkVersion = null; if (_cliOptions.EnableDynamicInstall) { _logger.LogDebug("Dynamic install is enabled."); var availableSdks = versionMap.Values; globalJsonSdkVersion = _globalJsonSdkResolver.GetSatisfyingSdkVersion( context.SourceRepo, context.ResolvedDotNetCoreRuntimeVersion, availableSdks); if (_platformInstaller.IsVersionAlreadyInstalled( context.ResolvedDotNetCoreRuntimeVersion, globalJsonSdkVersion)) { _logger.LogDebug( "DotNetCore runtime version {runtimeVersion} is already installed. " + "So skipping installing it again.", context.ResolvedDotNetCoreRuntimeVersion); } else { _logger.LogDebug( "DotNetCore runtime version {runtimeVersion} is not installed. " + "So generating an installation script snippet for it.", context.ResolvedDotNetCoreRuntimeVersion); installationScriptSnippet = _platformInstaller.GetInstallerScriptSnippet( context.ResolvedDotNetCoreRuntimeVersion, globalJsonSdkVersion); } } else { _logger.LogDebug("Dynamic install is not enabled."); } var manifestFileProperties = new Dictionary <string, string>(); manifestFileProperties[ManifestFilePropertyKeys.OperationId] = context.OperationId; manifestFileProperties[ManifestFilePropertyKeys.DotNetCoreRuntimeVersion] = context.ResolvedDotNetCoreRuntimeVersion; if (string.IsNullOrEmpty(globalJsonSdkVersion)) { manifestFileProperties[ManifestFilePropertyKeys.DotNetCoreSdkVersion] = versionMap[context.ResolvedDotNetCoreRuntimeVersion]; } else { manifestFileProperties[ManifestFilePropertyKeys.DotNetCoreSdkVersion] = globalJsonSdkVersion; } var projectFile = _projectFileProvider.GetRelativePathToProjectFile(context); if (string.IsNullOrEmpty(projectFile)) { return(null); } var templateProperties = new DotNetCoreBashBuildSnippetProperties { ProjectFile = projectFile, Configuration = GetBuildConfiguration(), }; var script = TemplateHelper.Render( TemplateHelper.TemplateResource.DotNetCoreSnippet, templateProperties, _logger); SetStartupFileNameInfoInManifestFile(context, projectFile, manifestFileProperties); return(new BuildScriptSnippet { BashBuildScriptSnippet = script, BuildProperties = manifestFileProperties, PlatformInstallationScriptSnippet = installationScriptSnippet, // Setting this to false to avoid copying files like '.cs' to the destination CopySourceDirectoryContentToDestinationDirectory = false, }); }