public void DnuPack_FrameworkSpecified(string flavor, string os, string architecture) { string expectedDNX = @"Building {0} for DNX,Version=v4.5.1 Using Project dependency {0} 1.0.0 Source: {1}/project.json".Replace('/', Path.DirectorySeparatorChar); string expectedNupkg = @"{0} -> {1}/bin/Debug/{0}.1.0.0.nupkg {0} -> {1}/bin/Debug/{0}.1.0.0.symbols.nupkg".Replace('/', Path.DirectorySeparatorChar); string stdOut; string stdError; var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); int exitCode; using (var testEnv = new DnuTestEnvironment(runtimeHomeDir)) { File.WriteAllText($"{testEnv.RootDir}/project.json", @"{ ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { ""dependencies"": { ""System.Runtime"":""4.0.20-*"" } } } }"); var environment = new Dictionary<string, string> { { "DNX_TRACE", "0" } }; DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", "", out stdOut, out stdError, environment: null, workingDir: testEnv.RootDir); exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "pack", "--framework dnx451", out stdOut, out stdError, environment, testEnv.RootDir); Assert.Empty(stdError); Assert.Contains(string.Format(expectedDNX, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.DoesNotContain("DNXCore", stdOut); Assert.Contains(string.Format(expectedNupkg, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Equal(0, exitCode); Assert.True(Directory.Exists($"{testEnv.RootDir}/bin")); } }
public void DnuRestore_ExecutesScripts(string flavor, string os, string architecture) { bool isWindows = TestUtils.CurrentRuntimeEnvironment.OperatingSystem == "Windows"; var environment = new Dictionary<string, string> { { "DNX_TRACE", "0" }, }; var expectedPreContent = @"""one"" ""two"" "">three"" ""four"" "; var expectedPostContent = @"""five"" ""six"" ""argument seven"" ""argument eight"" "; string projectJsonContent; string scriptContent; string scriptName; if (isWindows) { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script.cmd one two > pre"", ""script.cmd ^>three >> pre && script.cmd ^ four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script.cmd\"" five six > post"", ""\""%project:Directory%/script.cmd\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"@echo off :argumentStart if ""%~1""=="""" goto argumentEnd echo ""%~1"" shift goto argumentStart :argumentEnd"; scriptName = "script.cmd"; } else { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script one two > pre"", ""script.sh \\>three >> pre; ./script.sh four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script\"" five six > post"", ""\""%project:Directory%/script.sh\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"#!/usr/bin/env bash set -o errexit for arg in ""$@""; do printf ""\""%s\""\n"" ""$arg"" done"; scriptName = "script.sh"; } var projectStructure = $@"{{ '.': ['project.json', '{ scriptName }'] }}"; var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) { var projectPath = testEnv.ProjectPath; DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", projectJsonContent) .WithFileContents(scriptName, scriptContent) .WriteTo(projectPath); FileOperationUtils.MarkExecutable(Path.Combine(projectPath, scriptName)); string output; string error; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: null, stdOut: out output, stdErr: out error, environment: environment, workingDir: projectPath); Assert.Equal(0, exitCode); Assert.Empty(error); Assert.Contains("Executing script 'prerestore' in project.json", output); Assert.Contains("Executing script 'postrestore' in project.json", output); var preContent = File.ReadAllText(Path.Combine(projectPath, "pre")); Assert.Equal(expectedPreContent, preContent); var postContent = File.ReadAllText(Path.Combine(projectPath, "post")); Assert.Equal(expectedPostContent, postContent); } }
public void DnuFeeds_ListsAllSources(string flavor, string os, string architecture) { var environment = new Dictionary<string, string> { { "DNX_TRACE", "0" }, }; var rootConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <clear /> <!-- Remove the effects of any machine-level config --> <add key=""Source1"" value=""https://source1"" /> <add key=""Source2"" value=""https://source2"" /> </packageSources> </configuration>"; var subConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""Source3"" value=""https://source3"" /> </packageSources> <disabledPackageSources> <add key=""Source1"" value=""https://source1"" /> </disabledPackageSources> </configuration>"; var projectStructure = @"{ 'root': { 'NuGet.Config': """", 'sub': { 'NuGet.Config': """" } } }"; var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) { var projectPath = testEnv.ProjectPath; DirTree.CreateFromJson(projectStructure) .WithFileContents("root/NuGet.Config", rootConfig) .WithFileContents("root/sub/NuGet.Config", subConfig) .WriteTo(projectPath); string output; string error; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "feeds", arguments: "list root/sub", stdOut: out output, stdErr: out error, environment: environment, workingDir: projectPath); Assert.Equal(0, exitCode); Assert.Empty(error); // CI Machines and such have different sources in the user-global config // So we can't actually assert the exact content of the output. Assert.Contains($"https://source1 [Disabled]{Environment.NewLine} Origin: {Path.Combine(projectPath, "root", "NuGet.Config")}", output); Assert.Contains($"https://source2{Environment.NewLine} Origin: {Path.Combine(projectPath, "root", "NuGet.Config")}", output); Assert.Contains($"https://source3{Environment.NewLine} Origin: {Path.Combine(projectPath, "root", "sub", "NuGet.Config")}", output); } }
public void PublishExcludeWithLongPath(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'Config.json', 'Program.cs'], 'Data': { 'Input': ['data1.dat', 'data2.dat'], 'Backup': ['backup1.dat', 'backup2.dat'] }, 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'Config.json', 'Program.cs'], 'Data': { 'Input': ['data1.dat', 'data2.dat'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""publishExclude"": ""Data/Backup/**"", ""exclude"": ""node_modules"" }") .WriteTo(testEnv.ProjectPath); BuildLongPath(Path.Combine(testEnv.ProjectPath, "node_modules")); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""publishExclude"": ""Data/Backup/**"", ""exclude"": ""node_modules"" }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void GenerateBatchFilesAndBashScriptsWithPublishedRuntime(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); // Each runtime home only contains one runtime package, which is the one we are currently testing against var runtimeRoot = Directory.EnumerateDirectories(Path.Combine(runtimeHomeDir, "runtimes"), Constants.RuntimeNamePrefix + "*").First(); var runtimeName = new DirectoryInfo(runtimeRoot).Name; var projectStructure = @"{ '.': ['project.json'], 'packages': {} }"; var expectedOutputStructure = @"{ '.': ['run.cmd', 'run', 'kestrel.cmd', 'kestrel'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'] } }, 'packages': { 'RUNTIME_PACKAGE_NAME': {} } } }".Replace("PROJECT_NAME", _projectName).Replace("RUNTIME_PACKAGE_NAME", runtimeName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") }, { EnvironmentNames.Home, runtimeHomeDir }, { EnvironmentNames.Trace, "1" } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --runtime {1}", testEnv.PublishOutputDirPath, runtimeName), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var runtimeSubDir = DirTree.CreateFromDirectory(runtimeRoot) .RemoveFile(Path.Combine("bin", "lib", "Microsoft.Framework.PackageManager", "bin", "profile", "startup.prof")); var batchFileBinPath = string.Format(@"%~dp0approot\packages\{0}\bin\", runtimeName); var bashScriptBinPath = string.Format("$DIR/approot/packages/{0}/bin/", runtimeName); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), @"{ ""locked"": false, ""version"": LOCKFILEFORMAT_VERSION, ""projectFileDependencyGroups"": { """": [], ""DNX,Version=v4.5.1"": [], ""DNXCore,Version=v5.0"": [] }, ""libraries"": {} }".Replace("LOCKFILEFORMAT_VERSION", LockFileFormat.Version.ToString())) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents("run.cmd", BatchFileTemplate, batchFileBinPath, Constants.BootstrapperExeName, testEnv.ProjectName, "run") .WithFileContents("kestrel.cmd", BatchFileTemplate, batchFileBinPath, Constants.BootstrapperExeName, testEnv.ProjectName, "kestrel") .WithFileContents("run", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, bashScriptBinPath, Constants.BootstrapperExeName, "run") .WithFileContents("kestrel", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, bashScriptBinPath, Constants.BootstrapperExeName, "kestrel") .WithSubDir(Path.Combine("approot", "packages", runtimeName), runtimeSubDir); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void GenerateBatchFilesAndBashScriptsWithoutPublishedRuntime(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'], 'packages': {} }"; var expectedOutputStructure = @"{ '.': ['run.cmd', 'run', 'kestrel.cmd', 'kestrel'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'] } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), @"{ ""locked"": false, ""version"": LOCKFILEFORMAT_VERSION, ""projectFileDependencyGroups"": { """": [], ""DNX,Version=v4.5.1"": [], ""DNXCore,Version=v5.0"": [] }, ""libraries"": {} }".Replace("LOCKFILEFORMAT_VERSION", LockFileFormat.Version.ToString())) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents("run.cmd", BatchFileTemplate, string.Empty, Constants.BootstrapperExeName, testEnv.ProjectName, "run") .WithFileContents("kestrel.cmd", BatchFileTemplate, string.Empty, Constants.BootstrapperExeName, testEnv.ProjectName, "kestrel") .WithFileContents("run", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, string.Empty, Constants.BootstrapperExeName, "run") .WithFileContents("kestrel", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, string.Empty, Constants.BootstrapperExeName, "kestrel"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void CorrectlyExcludeFoldersStartingWithDots(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'File', '.FileStartingWithDot', 'File.Having.Dots'], '.FolderStaringWithDot': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], '.SubFolderStartingWithDot': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'Folder': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], '.SubFolderStartingWithDot': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'Folder.Having.Dots': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], '.SubFolderStartingWithDot': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'File', '.FileStartingWithDot', 'File.Having.Dots'], 'Folder': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'Folder.Having.Dots': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void FoldersAsFilePatternsAutoGlob(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'FileWithoutExtension'], 'UselessFolder1': { '.': ['file1.txt', 'file2.css', 'file_without_extension'], 'SubFolder': ['file3.js', 'file4.html', 'file_without_extension'] }, 'UselessFolder2': { '.': ['file1.txt', 'file2.css', 'file_without_extension'], 'SubFolder': ['file3.js', 'file4.html', 'file_without_extension'] }, 'UselessFolder3': { '.': ['file1.txt', 'file2.css', 'file_without_extension'], 'SubFolder': ['file3.js', 'file4.html', 'file_without_extension'] }, 'MixFolder': { 'UsefulSub': ['useful.txt', 'useful.css', 'file_without_extension'], 'UselessSub1': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub2': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub3': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub4': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub5': ['file1.js', 'file2.html', 'file_without_extension'] }, '.git': ['index', 'HEAD', 'log'], 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'], 'MixFolder': { 'UsefulSub': ['useful.txt', 'useful.css', 'file_without_extension'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""publishExclude"": [ ""FileWithoutExtension"", ""UselessFolder1"", ""UselessFolder2/"", ""UselessFolder3\\"", ""MixFolder/UselessSub1/"", ""MixFolder\\UselessSub2\\"", ""MixFolder/UselessSub3\\"", ""MixFolder/UselessSub4"", ""MixFolder\\UselessSub5"", "".git"" ] }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""publishExclude"": [ ""FileWithoutExtension"", ""UselessFolder1"", ""UselessFolder2/"", ""UselessFolder3\\"", ""MixFolder/UselessSub1/"", ""MixFolder\\UselessSub2\\"", ""MixFolder/UselessSub3\\"", ""MixFolder/UselessSub4"", ""MixFolder\\UselessSub5"", "".git"" ] }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void DnuPublishWebApp_UpdateExistingWebConfig(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'], 'public': ['index.html', 'web.config'], 'packages': {} }"; var expectedOutputStructure = @"{ 'wwwroot': ['web.config', 'index.html'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': ['project.json', 'project.lock.json'] } } }".Replace("PROJECT_NAME", _projectName); var originalWebConfigContents = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <nonRelatedElement> <add key=""non-related-key"" value=""OLD_VALUE"" /> </nonRelatedElement> <appSettings> <add key=""non-related-key"" value=""OLD_VALUE"" /> <add key=""{0}"" value=""OLD_VALUE"" /> <add key=""{1}"" value=""OLD_VALUE"" /> <add key=""{2}"" value=""OLD_VALUE"" /> <add key=""{3}"" value=""OLD_VALUE"" /> <add key=""{4}"" value=""OLD_VALUE"" /> </appSettings> </configuration>", Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); var outputWebConfigContents = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <nonRelatedElement> <add key=""non-related-key"" value=""OLD_VALUE"" /> </nonRelatedElement> <appSettings> <add key=""non-related-key"" value=""OLD_VALUE"" /> <add key=""{0}"" value="""" /> <add key=""{1}"" value=""..\approot\packages"" /> <add key=""{2}"" value="""" /> <add key=""{3}"" value="""" /> <add key=""{4}"" value=""..\approot\src\{{0}}"" /> </appSettings> </configuration>", Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""webroot"": ""../../../wwwroot"" }") .WithFileContents(Path.Combine("public", "web.config"), originalWebConfigContents) .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --wwwroot public --wwwroot-out wwwroot", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""webroot"": ""../../../wwwroot"" }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents(Path.Combine("wwwroot", "web.config"), outputWebConfigContents, testEnv.ProjectName); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void DnuPublishWebApp_SubfolderAsPublicFolder(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'Config.json', 'Program.cs'], 'public': { 'Scripts': ['bootstrap.js', 'jquery.js'], 'Images': ['logo.png'], 'UselessFolder': ['file.useless'] }, 'Views': { 'Home': ['index.cshtml'], 'Shared': ['_Layout.cshtml'] }, 'Controllers': ['HomeController.cs'], 'UselessFolder': ['file.useless'], 'packages': {} }"; var expectedOutputStructure = @"{ 'wwwroot': { 'web.config': '', 'Scripts': ['bootstrap.js', 'jquery.js'], 'Images': ['logo.png'], 'UselessFolder': ['file.useless'] }, 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'Config.json', 'Program.cs'], 'Views': { 'Home': ['index.cshtml'], 'Shared': ['_Layout.cshtml'] }, 'Controllers': ['HomeController.cs'], } } } }".Replace("PROJECT_NAME", _projectName); var outputWebConfigTemplate = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <appSettings> <add key=""{0}"" value="""" /> <add key=""{1}"" value=""..\approot\packages"" /> <add key=""{2}"" value="""" /> <add key=""{3}"" value="""" /> <add key=""{4}"" value=""..\approot\src\{{0}}"" /> </appSettings> </configuration>", Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""publishExclude"": ""**.useless"", ""webroot"": ""public"" }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --wwwroot-out wwwroot", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""publishExclude"": ""**.useless"", ""webroot"": ""../../../wwwroot"" }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents(Path.Combine("wwwroot", "web.config"), outputWebConfigTemplate, testEnv.ProjectName); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void WildcardMatchingFacts(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'], 'UselessFolder1': { '.': ['uselessfile1.txt', 'uselessfile2'], 'SubFolder': ['uselessfile3.js', 'uselessfile4'] }, 'UselessFolder2': { '.': ['uselessfile1.txt', 'uselessfile2'], 'SubFolder': ['uselessfile3.js', 'uselessfile4'] }, 'UselessFolder3': { '.': ['uselessfile1.txt', 'uselessfile2'], 'SubFolder': ['uselessfile3.js', 'uselessfile4'] }, 'MixFolder1': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] }, 'MixFolder2': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] }, 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'], 'MixFolder1': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] }, 'MixFolder2': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""publishExclude"": [ ""UselessFolder1\\**"", ""UselessFolder2/**/*"", ""UselessFolder3\\**/*.*"" ] }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""publishExclude"": [ ""UselessFolder1\\**"", ""UselessFolder2/**/*"", ""UselessFolder3\\**/*.*"" ] }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void VerifyDefaultPublishExcludePatterns(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'File', '.FileStartingWithDot'], 'bin': { 'AspNet.Loader.dll': '', 'Debug': ['test.exe', 'test.dll'] }, 'obj': { 'test.obj': '', 'References': ['ref1.dll', 'ref2.dll'] }, '.git': ['index', 'HEAD', 'log'], 'Folder': { '.svn': ['index', 'HEAD', 'log'], 'File': '', '.FileStartingWithDot': '' }, 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'File', '.FileStartingWithDot'], 'Folder': ['File', '.FileStartingWithDot'] } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void DnuPack_OutPathSpecified(string flavor, string os, string architecture) { string expectedNupkg = @"{0} -> {1}/CustomOutput/Debug/{0}.1.0.0.nupkg".Replace('/', Path.DirectorySeparatorChar); string expectedSymbol = @"{0} -> {1}/CustomOutput/Debug/{0}.1.0.0.symbols.nupkg".Replace('/', Path.DirectorySeparatorChar); string stdOut; string stdError; var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); int exitCode; using (var testEnv = new DnuTestEnvironment(runtimeHomeDir)) { File.WriteAllText($"{testEnv.RootDir}/project.json", @"{ ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { ""dependencies"": { ""System.Runtime"":""4.0.20-*"" } } } }"); DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", "", out stdOut, out stdError, environment: null, workingDir: testEnv.RootDir); exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "pack", "--out CustomOutput", out stdOut, out stdError, environment: null, workingDir: testEnv.RootDir); Assert.Empty(stdError); Assert.Contains(string.Format(expectedNupkg, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Contains(string.Format(expectedSymbol, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Equal(0, exitCode); Assert.True(Directory.Exists($"{testEnv.RootDir}/CustomOutput")); } }