Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Build 1.1.0-preview4 version of dotnet-publish-iis #299

Merged
merged 2 commits into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NuGetPackageVerifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"AdxVerificationCompositeRule"
],
"packages": {
"Microsoft.AspNetCore.Server.IISIntegration": { }
"Microsoft.AspNetCore.Server.IISIntegration": { },
"Microsoft.AspNetCore.Server.IISIntegration.Tools": { }
}
},
"Default": { // Rules to run for packages not listed in any other set.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Extensions.Cli.Utils
{
public static class AnsiColorExtensions
{
public static string Red(this string text)
{
return "\x1B[31m" + text + "\x1B[39m";
}

public static string Yellow(this string text)
{
return "\x1B[33m" + text + "\x1B[39m";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;

namespace Microsoft.Extensions.Cli.Utils
{
public class AnsiConsole
{
private AnsiConsole(TextWriter writer)
{
Writer = writer;

OriginalForegroundColor = Console.ForegroundColor;
}

private int _boldRecursion;

public static AnsiConsole GetOutput()
{
return new AnsiConsole(Console.Out);
}

public static AnsiConsole GetError()
{
return new AnsiConsole(Console.Error);
}

public TextWriter Writer { get; }

public ConsoleColor OriginalForegroundColor { get; }

private void SetColor(ConsoleColor color)
{
const int Light = 0x08;
int c = (int)color;

Console.ForegroundColor =
c < 0 ? color : // unknown, just use it
_boldRecursion > 0 ? (ConsoleColor)(c | Light) : // ensure color is light
(ConsoleColor)(c & ~Light); // ensure color is dark
}

private void SetBold(bool bold)
{
_boldRecursion += bold ? 1 : -1;
if (_boldRecursion > 1 || (_boldRecursion == 1 && !bold))
{
return;
}

// switches on _boldRecursion to handle boldness
SetColor(Console.ForegroundColor);
}

public void WriteLine(string message)
{
Write(message);
Writer.WriteLine();
}


public void Write(string message)
{
var escapeScan = 0;
for (;;)
{
var escapeIndex = message.IndexOf("\x1b[", escapeScan, StringComparison.Ordinal);
if (escapeIndex == -1)
{
var text = message.Substring(escapeScan);
Writer.Write(text);
break;
}
else
{
var startIndex = escapeIndex + 2;
var endIndex = startIndex;
while (endIndex != message.Length &&
message[endIndex] >= 0x20 &&
message[endIndex] <= 0x3f)
{
endIndex += 1;
}

var text = message.Substring(escapeScan, escapeIndex - escapeScan);
Writer.Write(text);
if (endIndex == message.Length)
{
break;
}

switch (message[endIndex])
{
case 'm':
int value;
if (int.TryParse(message.Substring(startIndex, endIndex - startIndex), out value))
{
switch (value)
{
case 1:
SetBold(true);
break;
case 22:
SetBold(false);
break;
case 30:
SetColor(ConsoleColor.Black);
break;
case 31:
SetColor(ConsoleColor.Red);
break;
case 32:
SetColor(ConsoleColor.Green);
break;
case 33:
SetColor(ConsoleColor.Yellow);
break;
case 34:
SetColor(ConsoleColor.Blue);
break;
case 35:
SetColor(ConsoleColor.Magenta);
break;
case 36:
SetColor(ConsoleColor.Cyan);
break;
case 37:
SetColor(ConsoleColor.Gray);
break;
case 39:
Console.ForegroundColor = OriginalForegroundColor;
break;
}
}
break;
}

escapeScan = endIndex + 1;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Extensions.Cli.Utils
{
// Stupid-simple console manager
public class Reporter
{
private static readonly Reporter NullReporter = new Reporter(console: null);
private static object _lock = new object();

private readonly AnsiConsole _console;

private Reporter(AnsiConsole console)
{
_console = console;
}

public static Reporter Output { get; } = new Reporter(AnsiConsole.GetOutput());
public static Reporter Error { get; } = new Reporter(AnsiConsole.GetError());

public void WriteLine(string message)
{
lock (_lock)
{
_console?.WriteLine(message);
}
}

public void WriteLine()
{
lock (_lock)
{
_console?.Writer?.WriteLine();
}
}

public void Write(string message)
{
lock (_lock)
{
_console?.Write(message);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>b1bc61b7-ba1d-4100-a2e8-49d00ce2771d</ProjectGuid>
<RootNamespace>Microsoft.AspNetCore.Server.IISIntegration.Tools</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
60 changes: 60 additions & 0 deletions src/Microsoft.AspNetCore.Server.IISIntegration.Tools/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Microsoft.Extensions.Cli.Utils;
using Microsoft.Extensions.CommandLineUtils;

namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
{
public class Program
{
public static int Main(string[] args)
{
var app = new CommandLineApplication
{
Name = "dotnet publish-iis",
FullName = "Asp.Net Core IIS Publisher",
Description = "IIS Publisher for the Asp.Net Core web applications",
};
app.HelpOption("-h|--help");

var publishFolderOption = app.Option("-p|--publish-folder", "The path to the publish output folder", CommandOptionType.SingleValue);
var frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Target framework of application being published", CommandOptionType.SingleValue);
var configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Target configuration of application being published", CommandOptionType.SingleValue);
var projectPath = app.Argument("<PROJECT>", "The path to the project (project folder or project.json) being published. If empty the current directory is used.");

app.OnExecute(() =>
{
var publishFolder = publishFolderOption.Value();
var framework = frameworkOption.Value();

if (publishFolder == null || framework == null)
{
app.ShowHelp();
return 2;
}

Reporter.Output.WriteLine($"Configuring the following project for use with IIS: '{publishFolder}'");

var exitCode = new PublishIISCommand(publishFolder, framework, configurationOption.Value(), projectPath.Value).Run();

Reporter.Output.WriteLine("Configuring project completed successfully");

return exitCode;
});

try
{
return app.Execute(args);
}
catch (Exception e)
{
Reporter.Error.WriteLine(e.Message.Red());
Reporter.Output.WriteLine(e.ToString().Yellow());
}

return 1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Reflection;
using System.Resources;

[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]
[assembly: AssemblyCompany("Microsoft Corporation.")]
[assembly: AssemblyCopyright("© Microsoft Corporation. All rights reserved.")]
[assembly: AssemblyProduct("Microsoft ASP.NET Core")]
Loading