Add dotnet-init
This commit is contained in:
parent
1c6087b8e1
commit
b566be5de8
7 changed files with 234 additions and 35 deletions
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>bc765fbf-ad7a-4a99-9902-5540c5a74181</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tools.Init</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
98
src/Microsoft.DotNet.Tools.Init/Program.cs
Normal file
98
src/Microsoft.DotNet.Tools.Init/Program.cs
Normal file
|
@ -0,0 +1,98 @@
|
|||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Init
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static string GetFileNameFromResourceName(string s)
|
||||
{
|
||||
// A.B.C.D.filename.extension
|
||||
string[] parts = s.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length < 2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// filename.extension
|
||||
return parts[parts.Length - 2] + "." + parts[parts.Length - 1];
|
||||
}
|
||||
|
||||
public int CreateEmptyProject()
|
||||
{
|
||||
var thisAssembly = typeof(Program).GetTypeInfo().Assembly;
|
||||
var resources = from resourceName in thisAssembly.GetManifestResourceNames()
|
||||
where resourceName.ToLowerInvariant().EndsWith(".cs") || resourceName.ToLowerInvariant().EndsWith(".json")
|
||||
select resourceName;
|
||||
|
||||
Dictionary<string, string> resourceNameToFileName = new Dictionary<string, string>();
|
||||
bool hasFilesToOverride = false;
|
||||
foreach (string resourceName in resources)
|
||||
{
|
||||
string fileName = GetFileNameFromResourceName(resourceName);
|
||||
|
||||
resourceNameToFileName.Add(resourceName, fileName);
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
Console.WriteLine("Creating new project would override file {0}.", fileName);
|
||||
hasFilesToOverride = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFilesToOverride)
|
||||
{
|
||||
Console.WriteLine("Creating new project failed.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
foreach (var kv in resourceNameToFileName)
|
||||
{
|
||||
using (var fileStream = File.Create(kv.Value))
|
||||
{
|
||||
using (var resource = thisAssembly.GetManifestResourceStream(kv.Key))
|
||||
{
|
||||
resource.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Created new project in {0}.", Directory.GetCurrentDirectory());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
var app = new CommandLineApplication();
|
||||
app.Name = "dotnet init";
|
||||
app.FullName = ".NET Initializer";
|
||||
app.Description = "Initializes empty project for .NET Platform";
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
var dotnetInit = new Program();
|
||||
app.OnExecute((Func<int>)dotnetInit.CreateEmptyProject);
|
||||
|
||||
try
|
||||
{
|
||||
return app.Execute(args);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.Error.WriteLine(ex);
|
||||
#else
|
||||
Console.Error.WriteLine(ex.Message);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
src/Microsoft.DotNet.Tools.Init/Template/Program.cs
Normal file
12
src/Microsoft.DotNet.Tools.Init/Template/Program.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
18
src/Microsoft.DotNet.Tools.Init/Template/project.json
Normal file
18
src/Microsoft.DotNet.Tools.Init/Template/project.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23428",
|
||||
"System.IO": "4.0.11-beta-23428",
|
||||
"System.Console": "4.0.0-beta-23428",
|
||||
"System.Runtime": "4.0.21-beta-23428",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23428"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
32
src/Microsoft.DotNet.Tools.Init/project.json
Normal file
32
src/Microsoft.DotNet.Tools.Init/project.json
Normal file
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name" : "dotnet-init",
|
||||
"version": "1.0.0-*",
|
||||
"compilationOptions": {
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Runtime": "1.0.1-beta-23504",
|
||||
|
||||
"System.Console": "4.0.0-beta-23504",
|
||||
"System.Collections": "4.0.11-beta-23504",
|
||||
"System.Linq": "4.0.1-beta-23504",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-23504",
|
||||
"System.IO.FileSystem": "4.0.1-beta-23504",
|
||||
"System.AppContext": "4.0.1-beta-23504",
|
||||
|
||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"type": "build",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"Microsoft.Extensions.CommandLineUtils.Sources": {
|
||||
"type": "build",
|
||||
"version": "1.0.0-*"
|
||||
}
|
||||
},
|
||||
"compileExclude": [ "Template/**" ],
|
||||
"resource": [ "Template/**" ],
|
||||
"frameworks": {
|
||||
"dnxcore50": { }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue