Skip to content

Commit

Permalink
Added creation of a solution file when creating a new package
Browse files Browse the repository at this point in the history
  • Loading branch information
MakarchukPavel committed Feb 6, 2020
1 parent 555ba3f commit 586e7e9
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions clio/Package/CreatioPackage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using Clio.UserEnvironment;
using Newtonsoft.Json;
Expand All @@ -11,6 +12,7 @@ public class CreatioPackage
public const string DescriptorName = "descriptor.json";
public const string PropertiesDirName = "Properties";
public const string CsprojExtension = "csproj";
public const string SlnExtension = "sln";
public const string PackageConfigName = "packages.config";
public const string AssemblyInfoName = "AssemblyInfo.cs";
public const string PlaceholderFileName = "placeholder.txt";
Expand All @@ -22,7 +24,9 @@ public class CreatioPackage

private static string DescriptorTpl => $"tpl{Path.DirectorySeparatorChar}{DescriptorName}.tpl";
private static string ProjTpl => $"tpl{Path.DirectorySeparatorChar}Proj.{CsprojExtension}.tpl";

private string ProjectFileName => $"{PackageName}.{CsprojExtension}";
private string SolutionName => PackageName;
private string SolutionFileName => $"{SolutionName}.{SlnExtension}";
private readonly ICreatioEnvironment _creatioEnvironment;


Expand Down Expand Up @@ -81,6 +85,20 @@ public class CreatioPackage
return false;
}

private void ExecuteDotnetCommand(string command) {
var process = new Process();
process.StartInfo = new ProcessStartInfo() {
FileName = "dotnet",
Arguments = command,
CreateNoWindow = true,
UseShellExecute = false,
WorkingDirectory = FullPath
};
process.EnableRaisingEvents = true;
process.Start();
process.WaitForExit();
}

public static string GetExecutingDirectorybyAppDomain() {
string path = AppDomain.CurrentDomain.BaseDirectory;
return path;
Expand All @@ -107,11 +125,17 @@ public class CreatioPackage
}

protected CreatioPackage CreateProj() {
var filePath = Path.Combine(FullPath, PackageName + "." + CsprojExtension);
var filePath = Path.Combine(FullPath, ProjectFileName);
CreateFromTpl(ProjTpl, filePath);
return this;
}

protected CreatioPackage CreateSolution() {
ExecuteDotnetCommand($"new sln -n {SolutionName}");
ExecuteDotnetCommand($"sln {SolutionFileName} add {ProjectFileName}");
return this;
}

protected CreatioPackage CreatePackageConfig() {
var filePath = Path.Combine(FullPath, PackageConfigName);
CreateFromTpl(PackageConfigTpl, filePath);
Expand Down Expand Up @@ -142,6 +166,7 @@ public class CreatioPackage
protected CreatioPackage CreatePackageFiles() {
CreatePkgDescriptor()
.CreateProj()
.CreateSolution()
.CreatePackageConfig()
.CreateAssemblyInfo()
.CreateEmptyClass();
Expand Down

0 comments on commit 586e7e9

Please sign in to comment.