/// <inheritdoc /> public ScriptProjectInfo CreateProject(string targetDirectory, string targetFramework = "net46") { var csxFiles = Directory.GetFiles(targetDirectory, "*.csx", SearchOption.AllDirectories); var parseresult = scriptParser.ParseFrom(csxFiles); if (parseresult.TargetFramework != null) { targetFramework = parseresult.TargetFramework; } var pathToProjectJson = GetPathToProjectJson(targetDirectory); var projectJson = new ProjectJson(); projectJson.Frameworks.Add(targetFramework, new Dictionary <string, List <string> >()); // Add the most common imports when resolving in the context of .Net Core if (targetFramework.StartsWith("netcoreapp", StringComparison.OrdinalIgnoreCase)) { projectJson.Frameworks.First().Value.Add("imports", new List <string>(new[] { "dotnet", "dnxcore50" })); } var packageReferences = parseresult.PackageReferences; foreach (var packageReference in packageReferences) { projectJson.Dependencies.Add(packageReference.Id, packageReference.Version); } projectJson.Save(pathToProjectJson); Restore(pathToProjectJson); return(new ScriptProjectInfo(pathToProjectJson, targetFramework)); }
public string CreateProject(string targetDirectory) { var csxFiles = Directory.GetFiles(targetDirectory, "*.csx", SearchOption.AllDirectories); var parseresult = scriptParser.ParseFrom(csxFiles); var pathToProjectFile = GetPathToProjectFile(targetDirectory); var projectFile = new ProjectFile(); foreach (var packageReference in parseresult.PackageReferences) { projectFile.AddPackageReference(packageReference); } projectFile.Save(pathToProjectFile); logger.LogInformation($"Project file saved to {pathToProjectFile}"); return(pathToProjectFile); }