Exemplo n.º 1
0
 private static void AssertDefaultTargets(string lockFilePath, FrameworkName framework)
 {
     var lockFile = new LockFileReader().Read(lockFilePath);
     Assert.True(lockFile.HasTarget(framework));
     foreach(var rid in PlatformServices.Default.Runtime.GetDefaultRestoreRuntimes())
     {
         Assert.True(lockFile.HasTarget(framework, rid));
     }
 }
Exemplo n.º 2
0
        public void GenerateBatchFilesAndBashScriptsWithPublishedRuntime(string flavor, string os, string architecture, string configuration)
        {
            var runtimeHomeDir = _fixture.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 = @"{
  'approot': {
    '.': ['run.cmd', 'run', 'kestrel.cmd', 'kestrel'],
    'global.json': '',
    'src': {
      'PROJECT_NAME': {
        '.': ['project.json', 'project.lock.json']
      }
    },
    'packages': {},
    'runtimes': {
      '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 Microsoft.AspNet.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 arguments = $"--out {testEnv.PublishOutputDirPath} --runtime {runtimeName}";
                if (configuration != null)
                {
                    arguments += $" --configuration {configuration}";
                }
                else
                {
                    // default value "Debug" is always set. this variable is used in verification later.
                    configuration = "Debug";
                }

                var exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    subcommand: "publish",
                    arguments: arguments,
                    environment: environment,
                    workingDir: testEnv.ProjectPath);
                Assert.Equal(0, exitCode);

                var runtimeSubDir = DirTree.CreateFromDirectory(runtimeRoot)
                    .RemoveFile(Path.Combine("bin", "lib", "Microsoft.Dnx.Tooling",
                        "bin", "profile", "startup.prof"));

                var batchFileBinPath = string.Format(@"%~dp0runtimes\{0}\bin\", runtimeName);
                var bashScriptBinPath = string.Format("$DIR/runtimes/{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 Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5004""
  },
  ""frameworks"": {
    ""dnx451"": { },
    ""dnxcore50"": { }
  }
}")
                    .WithFileContents(Path.Combine("approot", "global.json"), @"{
  ""projects"": [
    ""src""
  ],
  ""packages"": ""packages""
}")
                    .WithFileContents(Path.Combine("approot", "run.cmd"), BatchFileTemplate, runtimeName, Constants.BootstrapperExeName, testEnv.ProjectName, configuration, "run")
                    .WithFileContents(Path.Combine("approot", "kestrel.cmd"), BatchFileTemplate, runtimeName, Constants.BootstrapperExeName, testEnv.ProjectName, configuration, "kestrel")
                    .WithFileContents(Path.Combine("approot", "run"),
                        BashScriptTemplate, testEnv.ProjectName, bashScriptBinPath, Constants.BootstrapperExeName, configuration, "run")
                    .WithFileContents(Path.Combine("approot", "kestrel"),
                        BashScriptTemplate, testEnv.ProjectName, bashScriptBinPath, Constants.BootstrapperExeName, configuration, "kestrel")
                    .WithSubDir(Path.Combine("approot", "runtimes", runtimeName), runtimeSubDir);

                Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath,
                    compareFileContents: true));

                var lockFile = new LockFileReader().Read(Path.Combine(testEnv.PublishOutputDirPath, "approot", "src", testEnv.ProjectName, "project.lock.json"));
                var fx = flavor == "coreclr" ? DnxCore50 : Dnx451;
                Assert.True(lockFile.HasTarget(fx));

                // GetRuntimeIdentifiers is tested separately, we're testing that the targets made the lock file here.
                var rids = Publish.DependencyContext.GetRuntimeIdentifiers(runtimeName);
                foreach(var rid in rids)
                {
                    Assert.True(lockFile.HasTarget(fx, rid));
                }
            }
        }