Merge branch 'release' into dev

This commit is contained in:
John Luo 2016-04-06 14:04:21 -07:00
commit bc94654a75
7 changed files with 37 additions and 156 deletions

View File

@ -9,25 +9,16 @@
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"web": "IISSample"
},
"frameworks": {
"net451": { },
"netstandardapp1.5": {
"imports": "portable-net451+win8"
"dependencies": {
"NETStandard.Library": "1.5.0-*"
},
"imports": "dnxcore50"
}
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
"content": [
"web.config"
]
}

View File

@ -14,13 +14,12 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
var app = new CommandLineApplication
{
Name = "dotnet publish-iis",
FullName = "Asp.Net IIS Publisher",
Description = "IIS Publisher for the Asp.Net web applications",
FullName = "Asp.Net Core IIS Publisher",
Description = "IIS Publisher for the Asp.Net Core web applications",
};
app.HelpOption("-h|--help");
var publishFolderOption = app.Option("--publish-folder|-p", "The path to the publish output folder", CommandOptionType.SingleValue);
var webRootOption = app.Option("--webroot|-w", "The name of webroot folder", 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(() =>
@ -35,7 +34,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
Reporter.Output.WriteLine($"Configuring the following project for use with IIS: '{publishFolder}'");
var exitCode = new PublishIISCommand(publishFolder, projectPath.Value, webRootOption.Value()).Run();
var exitCode = new PublishIISCommand(publishFolder, projectPath.Value).Run();
Reporter.Output.WriteLine("Configuring project completed successfully");

View File

@ -15,23 +15,19 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
{
private readonly string _publishFolder;
private readonly string _projectPath;
private readonly string _webRoot;
public PublishIISCommand(string publishFolder, string projectPath, string webRoot)
public PublishIISCommand(string publishFolder, string projectPath)
{
_publishFolder = publishFolder;
_projectPath = projectPath;
_webRoot = webRoot;
}
public int Run()
{
var applicationBasePath = GetApplicationBasePath();
var webRoot = GetWebRoot(applicationBasePath);
XDocument webConfigXml = null;
var webRootDirectory = Path.Combine(_publishFolder, webRoot);
var webConfigPath = Path.Combine(webRootDirectory, "web.config");
var webConfigPath = Path.Combine(_publishFolder, "web.config");
if (File.Exists(webConfigPath))
{
Reporter.Output.WriteLine($"Updating web.config at '{webConfigPath}'");
@ -44,12 +40,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
}
else
{
if (!Directory.Exists(webRootDirectory))
{
Reporter.Output.WriteLine($"No webroot directory found. Creating '{webRootDirectory}'");
Directory.CreateDirectory(webRootDirectory);
}
Reporter.Output.WriteLine($"No web.config found. Creating '{webConfigPath}'");
}
@ -83,32 +73,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
return ProjectReader.GetProject(Path.Combine(applicationBasePath, "project.json")).Name;
}
private string GetWebRoot(string applicationBasePath)
{
if (!string.IsNullOrEmpty(_webRoot))
{
return _webRoot;
}
var builder = new ConfigurationBuilder()
.SetBasePath(applicationBasePath)
.AddJsonFile("hosting.json", optional: true);
var webroot = builder.Build()["webroot"];
if (!string.IsNullOrEmpty(webroot))
{
return webroot;
}
if (Directory.Exists(Path.Combine(applicationBasePath, "wwwroot")))
{
return "wwwroot";
}
return string.Empty;
}
private static bool ConfigureForAzure()
{
var configureForAzureValue = Environment.GetEnvironmentVariable("DOTNET_CONFIGURE_AZURE");

View File

@ -57,32 +57,13 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools
private static void TransformAspNetCore(XElement aspNetCoreElement, string appName, bool configureForAzure)
{
var appPath = Path.Combine(configureForAzure ? @"%home%\site" : "..", appName);
var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @"..\logs", "stdout.log");
var appPath = Path.Combine(configureForAzure ? @"%home%\site" : ".", appName);
var logPath = Path.Combine(configureForAzure ? @"\\?\%home%\LogFiles" : @".\logs", "stdout.log");
aspNetCoreElement.SetAttributeValue("processPath", appPath);
SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogEnabled", "false");
SetAttributeValueIfEmpty(aspNetCoreElement, "stdoutLogFile", logPath);
SetAttributeValueIfEmpty(aspNetCoreElement, "startupTimeLimit", "3600");
AddApplicationBase(aspNetCoreElement);
}
private static void AddApplicationBase(XElement aspNetCoreElement)
{
const string contentRootKeyName = "ASPNETCORE_CONTENTROOT";
var envVariables = GetOrCreateChild(aspNetCoreElement, "environmentVariables");
var appBaseElement = envVariables.Elements("environmentVariable").SingleOrDefault(e =>
string.Equals((string)e.Attribute("name"), contentRootKeyName, StringComparison.CurrentCultureIgnoreCase));
if (appBaseElement == null)
{
appBaseElement = new XElement("environmentVariable", new XAttribute("name", contentRootKeyName));
envVariables.AddFirst(appBaseElement);
}
appBaseElement.SetAttributeValue("value", ".");
}
private static XElement GetOrCreateChild(XElement parent, string childName)

View File

@ -18,15 +18,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
[Fact]
public void PublishIIS_uses_default_values_if_options_not_specified()
{
var webRoot = "wwwroot";
var folders = CreateTestDir("{}", webRoot);
var folders = CreateTestDir("{}");
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run();
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput)
.Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal($@"..\projectDir.exe", processPath);
Assert.Equal($@".\projectDir.exe", processPath);
Directory.Delete(folders.TestRoot, recursive: true);
}
@ -36,49 +35,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
[InlineData("awesome.App")]
public void PublishIIS_reads_application_name_from_project_json_if_exists(string projectName)
{
var webRoot = "wwwroot";
var folders = CreateTestDir($@"{{ ""name"": ""{projectName}"" }}", webRoot);
var folders = CreateTestDir($@"{{ ""name"": ""{projectName}"" }}");
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run();
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput)
.Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal($@"..\{projectName}.exe", processPath);
Directory.Delete(folders.TestRoot, recursive: true);
}
[Fact]
public void PublishIIS_uses_webroot_from_hosting_json()
{
var webRoot = "mywebroot";
var folders = CreateTestDir("{}", webRoot);
File.WriteAllText(Path.Combine(folders.ProjectPath, "hosting.json"), $"{{ \"webroot\": \"{webRoot}\"}}");
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, null).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal(@"..\projectDir.exe", processPath);
Directory.Delete(folders.TestRoot, recursive: true);
}
[Fact]
public void PublishIIS_webroot_switch_takes_precedence_over_hosting_json()
{
var webRoot = "mywebroot";
var folders = CreateTestDir("{}", webRoot);
File.WriteAllText(Path.Combine(folders.ProjectPath, "hosting.json"), $"{{ \"webroot\": \"wwwroot\"}}");
new PublishIISCommand(folders.PublishOutput, folders.ProjectPath, webRoot).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
.Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal(@"..\projectDir.exe", processPath);
Assert.Equal($@".\{projectName}.exe", processPath);
Directory.Delete(folders.TestRoot, recursive: true);
}
@ -88,15 +52,14 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
[InlineData("project.Dir")]
public void PublishIIS_accepts_path_to_project_json_as_project_path(string projectDir)
{
var webRoot = "wwwroot";
var folders = CreateTestDir("{}", webRoot, projectDir);
var folders = CreateTestDir("{}", projectDir);
new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json"), null).Run();
new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json")).Run();
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput, webRoot)
var processPath = (string)GetPublishedWebConfig(folders.PublishOutput)
.Descendants("aspNetCore").Attributes("processPath").Single();
Assert.Equal($@"..\{projectDir}.exe", processPath);
Assert.Equal($@".\{projectDir}.exe", processPath);
Directory.Delete(folders.TestRoot, recursive: true);
}
@ -104,10 +67,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
[Fact]
public void PublishIIS_modifies_existing_web_config()
{
var webRoot = "wwwroot";
var folders = CreateTestDir("{}", webRoot);
var folders = CreateTestDir("{}");
File.WriteAllText(Path.Combine(folders.PublishOutput, webRoot, "web.config"),
File.WriteAllText(Path.Combine(folders.PublishOutput, "web.config"),
@"<configuration>
<system.webServer>
<handlers>
@ -117,35 +79,33 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
</system.webServer>
</configuration>");
new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json"), null).Run();
new PublishIISCommand(folders.PublishOutput, Path.Combine(folders.ProjectPath, "project.json")).Run();
var aspNetCoreElement = GetPublishedWebConfig(folders.PublishOutput, webRoot)
var aspNetCoreElement = GetPublishedWebConfig(folders.PublishOutput)
.Descendants("aspNetCore").Single();
Assert.Equal(@"..\projectDir.exe", (string)aspNetCoreElement.Attribute("processPath"));
Assert.Equal(@".\projectDir.exe", (string)aspNetCoreElement.Attribute("processPath"));
Assert.Equal(@"1234", (string)aspNetCoreElement.Attribute("startupTimeLimit"));
Directory.Delete(folders.TestRoot, recursive: true);
}
private XDocument GetPublishedWebConfig(string publishOut, string webRoot)
private XDocument GetPublishedWebConfig(string publishOut)
{
return XDocument.Load(Path.Combine(publishOut, webRoot, "web.config"));
return XDocument.Load(Path.Combine(publishOut, "web.config"));
}
private Folders CreateTestDir(string projectJson, string webRoot, string projectDir = "projectDir")
private Folders CreateTestDir(string projectJson, string projectDir = "projectDir")
{
var testRoot = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(testRoot);
var projectPath = Path.Combine(testRoot, projectDir);
Directory.CreateDirectory(projectPath);
Directory.CreateDirectory(Path.Combine(projectPath, webRoot));
File.WriteAllText(Path.Combine(projectPath, "project.json"), projectJson);
var publishOut = Path.Combine(testRoot, "publishOut");
Directory.CreateDirectory(publishOut);
Directory.CreateDirectory(Path.Combine(publishOut, webRoot));
return new Folders { TestRoot = testRoot, ProjectPath = projectPath, PublishOutput = publishOut };
}

View File

@ -12,11 +12,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
<handlers>
<add name=""aspNetCore"" path=""*"" verb=""*"" modules=""AspNetCoreModule"" resourceType=""Unspecified""/>
</handlers>
<aspNetCore processPath=""..\test.exe"" stdoutLogEnabled=""false"" stdoutLogFile=""..\logs\stdout.log"" startupTimeLimit=""3600"">
<environmentVariables>
<environmentVariable name=""ASPNETCORE_CONTENTROOT"" value=""."" />
</environmentVariables>
</aspNetCore>
<aspNetCore processPath="".\test.exe"" stdoutLogEnabled=""false"" stdoutLogFile="".\logs\stdout.log"" startupTimeLimit=""3600""/>
</system.webServer>
</configuration>");
@ -79,7 +75,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
(string)WebConfigTransform.Transform(WebConfigTemplate, "app.exe", configureForAzure: false)
.Descendants("aspNetCore").Single().Attribute("processPath");
Assert.Equal(@"..\app.exe", newProcessPath);
Assert.Equal(@".\app.exe", newProcessPath);
}
[Fact]
@ -99,7 +95,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
new XElement("environmentVariable", new XAttribute("name", "ENVVAR"), new XAttribute("value", "123"));
var input = WebConfigTemplate;
input.Descendants("environmentVariable").Single().Add(envVarElement);
input.Descendants("aspNetCore").Single().Add(envVarElement);
Assert.True(XNode.DeepEquals(envVarElement,
WebConfigTransform.Transform(input, "app.exe", configureForAzure: false)
@ -134,7 +130,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
}
Assert.Equal(
@"..\logs\stdout.log",
@".\logs\stdout.log",
(string)WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)
.Descendants().Attributes("stdoutLogFile").Single());
}
@ -177,16 +173,6 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.Tools.Tests
aspNetCoreElement));
}
[Fact]
public void WebConfigTransform_overrites_value_for_ASPNET_APPLICATIONBASE()
{
var input = WebConfigTemplate;
input.Descendants("environmentVariable").Single().SetAttributeValue("value", "abc");
Assert.True(XNode.DeepEquals(WebConfigTemplate,
WebConfigTransform.Transform(input, "test.exe", configureForAzure: false)));
}
private bool VerifyMissingElementCreated(params string[] elementNames)
{
var input = WebConfigTemplate;