public DockerfileContext BuildContext(DockerfileOption option) { if (!File.Exists(option.ProjectPath)) { throw new ArgumentException($"The file '{option.ProjectPath}' don't exits."); } string fullProjectPath = Path.GetFullPath(option.ProjectPath); string fullCsprojDir = Path.GetDirectoryName(fullProjectPath); string slnDir = FindSolutionDir(fullCsprojDir); string csprojDir = Path.GetRelativePath(slnDir, fullCsprojDir); string csprojName = Path.GetFileName(option.ProjectPath); string targetDockerfile = Path.Combine(fullCsprojDir, "Dockerfile"); var csprojDocument = System.Xml.Linq.XDocument.Load(fullProjectPath); var root = csprojDocument.Root; var netVersionElement = root.Element("PropertyGroup").Element("TargetFramework"); var assemblyNameElement = root.Element("PropertyGroup").Element("AssemblyName"); string entryDllName = assemblyNameElement == null? Path.GetFileNameWithoutExtension(csprojName) + ".dll" : assemblyNameElement.Value + ".dll"; return(new DockerfileContext { BuildMode = option.BuildMode, CsprojDir = csprojDir, CsprojName = csprojName, Force = option.Force, RootDir = slnDir, TargetDockerfile = targetDockerfile, EntryDllName = entryDllName, NetCoreVersion = ExtractNetCoreVersion(netVersionElement.Value) }); }
public int Run(DockerfileOption option) { try { var context = this.BuildContext(option); new DockerfileGenerator().Generator(context); } catch (Exception ex) { Console.WriteLine(option.Debug ? ex.ToString() : ex.Message); return(1); } return(0); }