public string WriteToFileSystem(Solution solution, string outputPath) { if (solution is null) { throw new ArgumentNullException(nameof(solution)); } var createSolutionCommand = DotNet.New(_outputWriter).Solution().InFolder(outputPath).WithName(solution.Name).Build(); createSolutionCommand.Execute((innerException) => new ProjectCreationNotPossibleException("Could not create solution.", innerException)); string solutionFilePath = Path.Combine(outputPath, $"{solution.Name}.sln"); WriteProjects(solution, outputPath, solutionFilePath); if (solution.NugetConfig != null) { _projectFileWriter.Write(solution.NugetConfig, outputPath); } var targetFramework = solution.Projects .Select(p => p.TargetFrameworks) .FirstOrDefault(); var sdk = _netCoreSdkInfoProvider.GetSdkFromTargetFramework(targetFramework); if (targetFramework != 0 && sdk != null) { var globalJsonBuilder = new GlobalJsonBuilder().WithSdk(sdk); var globalJsonFile = globalJsonBuilder.ToProjectFile(); _projectFileWriter.Write(globalJsonFile, outputPath); } return(solutionFilePath); }
private void CreateProjectFile(Project project, string projRootPath) { string template; switch (project.ProjectType) { case ProjectType.Library: template = "classlib"; break; case ProjectType.Exe: template = "console"; break; case ProjectType.ASPNetCore: template = "web"; break; default: throw new ArgumentOutOfRangeException(nameof(project.ProjectType), $"ProjectType {project.ProjectType} is not supported"); } var newProjCommand = DotNet.New(_outputWriter) .Project() .InFolder(projRootPath) .WithName(project.Name) .UsingTemplate(template) .WithLanguage(project.ProgrammingLanguage) .Build(); newProjCommand.Execute(innerExceptions => new ProjectCreationNotPossibleException("Execution of dotnet new failed.", innerExceptions)); }
public string WriteToFileSystem(Solution solution, string outputPath) { if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } if (solution is null) { throw new ArgumentNullException(nameof(solution)); } var targetFramework = solution.Projects .Select(p => p.TargetFrameworks) .FirstOrDefault(); var sdk = !string.IsNullOrWhiteSpace(solution.SdkVersion) ? new NetCoreSdkInfo(solution.SdkVersion) : _netCoreSdkInfoProvider.GetSdkFromTargetFramework(targetFramework); if (targetFramework != 0 && sdk != null) { var globalJsonBuilder = new GlobalJsonBuilder().WithSdk(sdk); var globalJsonFile = globalJsonBuilder.ToProjectFile(); _fileWriter.Write(globalJsonFile, outputPath); } AllowNet6ToTestOlderFrameworks(targetFramework); var createSolutionCommand = DotNet.New(_outputWriter).Solution().InFolder(outputPath).WithName(solution.Name).Build(); createSolutionCommand.ExecuteWithRetry(1, TimeSpan.FromSeconds(1), (innerException) => new ProjectCreationNotPossibleException("Could not create solution.", innerException)); string solutionFilePath = Path.Combine(outputPath, $"{solution.Name}.sln"); WriteProjects(solution, outputPath, solutionFilePath); if (solution.NugetConfig != null) { _fileWriter.Write(solution.NugetConfig, outputPath); } foreach (var file in solution.Files) { _fileWriter.Write(file, outputPath); } return(solutionFilePath); }
private void CreateProjectFile(Project project, string projRootPath) { string template = project.ProjectType == ProjectType.Exe ? "console" : "classlib"; var newProjCommand = DotNet.New(_outputWriter) .Project() .InFolder(projRootPath) .WithName(project.Name) .UsingTemplate(template) .WithLanguage(project.ProgrammingLanguage) .Build(); newProjCommand.Execute(innerExceptions => new ProjectCreationNotPossibleException("Execution of dotnet new failed.", innerExceptions)); }
public string WriteToFileSystem(Solution solution, string outputPath) { if (solution is null) { throw new ArgumentNullException(nameof(solution)); } var createSolutionCommand = DotNet.New(_outputWriter).Solution().InFolder(outputPath).WithName(solution.Name).Build(); createSolutionCommand.Execute((innerException) => new ProjectCreationNotPossibleException("Could not create solution.", innerException)); string solutionFilePath = Path.Combine(outputPath, $"{solution.Name}.sln"); WriteProjects(solution, outputPath, solutionFilePath); if (solution.NugetConfig != null) { _projectFileWriter.Write(solution.NugetConfig, outputPath); } //_projectFileWriter.Write(new ProjectFile("global.json", "None", "{ \"sdk\": { \"version\": \"2.1.105\" }}"), outputPath); return(solutionFilePath); }