public void BuildingAPortableProjectProducesDepsFile() { var testInstance = TestAssetsManager.CreateTestInstance("BuildTestPortableProject") .WithLockFiles(); var result = new BuildCommand( projectPath: testInstance.TestRoot, forcePortable: true) .ExecuteWithCapturedOutput(); result.Should().Pass(); var outputBase = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "bin", "Debug")); var netstandardappOutput = outputBase.Sub("netstandardapp1.5"); netstandardappOutput.Should() .Exist().And .HaveFiles(new[] { "BuildTestPortableProject.deps", "BuildTestPortableProject.deps.json", "BuildTestPortableProject.dll", "BuildTestPortableProject.pdb" }); }
public void XmlDocumentationFileIsGenerated() { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); var testLibDir = root.CreateDirectory("TestLibrary"); // copy projects to the temp dir and restore them CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); RunRestore(testLibDir.Path); // run compile var outputDir = Path.Combine(testLibDir.Path, "bin"); var testProject = GetProjectPath(testLibDir); var buildCommand = new BuildCommand(testProject, output: outputDir); var result = buildCommand.ExecuteWithCapturedOutput(); result.Should().Pass(); // Should have triggered some compiler warnings about missing XML doc comments Assert.True(result.StdErr.Contains("warning CS1591")); // verify the output xml file var outputXml = Path.Combine(outputDir, "TestLibrary.xml"); Assert.True(File.Exists(outputXml)); Assert.Contains("Gets the message from the helper", File.ReadAllText(outputXml)); }
private void Setup([CallerMemberName] string callingMethod = "") { var testInstance = TestAssetsManager.CreateTestInstance(Path.Combine("ProjectsWithTests", "MultipleFrameworkProject"), callingMethod); _projectFilePath = Path.Combine(testInstance.TestRoot, "project.json"); var contexts = ProjectContext.CreateContextForEachFramework( _projectFilePath, null, RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); // Restore the project again in the destination to resolve projects // Since the lock file has project relative paths in it, those will be broken // unless we re-restore new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute().Should().Pass(); _netCoreAppOutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0"); var buildCommand = new BuildCommand(_projectFilePath); var result = buildCommand.Execute($"-f netcoreapp1.0 -o {_netCoreAppOutputPath}"); result.Should().Pass(); if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) { var rid = RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers().First(); _net451OutputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "net451", rid); result = buildCommand.Execute($"-f net451 -r {rid} -o {_net451OutputPath}"); result.Should().Pass(); } }
public void ItBinplacesContentOnBuildForConsoleApps() { var projectDirectory = TestAssets .GetProjectJson("TestAppWithContents") .CreateInstance() .WithSourceFiles() .WithRestoreFiles() .WithEmptyGlobalJson() .Root; new MigrateTestCommand() .WithWorkingDirectory(projectDirectory) .Execute($"{projectDirectory.FullName}") .Should() .Pass(); var command = new RestoreCommand() .WithWorkingDirectory(projectDirectory) .Execute() .Should() .Pass(); var result = new BuildCommand() .WithWorkingDirectory(projectDirectory) .ExecuteWithCapturedOutput() .Should() .Pass(); var outputDir = projectDirectory.GetDirectory("bin", "Debug", "netcoreapp1.0"); outputDir.Should().Exist().And.HaveFile("testcontentfile.txt"); outputDir.GetDirectory("dir").Should().Exist().And.HaveFile("mappingfile.txt"); }
public void It_resolves_desktop_apps_when_configuration_is_Debug() { var configuration = "Debug"; var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects")); var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyDesktopAndPortable") .WithLockFiles(); var buildCommand = new BuildCommand( Path.Combine(testInstance.TestRoot, "project.json"), configuration: configuration) .ExecuteWithCapturedOutput() .Should() .Pass(); var context = ProjectContext.Create(testInstance.TestRoot, s_desktopTestFramework); var factory = new ProjectDependenciesCommandFactory( s_desktopTestFramework, configuration, null, null, testInstance.TestRoot); var command = factory.Create("dotnet-desktop-and-portable", null); command.CommandName.Should().Contain(Path.Combine(testInstance.TestRoot, "bin", configuration)); Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe"); }
private static void BuildAndTest(string testRoot) { string appName = Path.GetFileName(testRoot); var result = new BuildCommand( projectPath: testRoot) .ExecuteWithCapturedOutput(); result.Should().Pass(); var outputBase = new DirectoryInfo(Path.Combine(testRoot, "bin", "Debug")); var netcoreAppOutput = outputBase.Sub("netcoreapp1.0"); netcoreAppOutput.Should() .Exist().And .OnlyHaveFiles(new[] { $"{appName}.deps.json", $"{appName}.dll", $"{appName}.pdb", $"{appName}.runtimeconfig.json", $"{appName}.runtimeconfig.dev.json" }); }
private string BuildMSBuild( DirectoryInfo projectDirectory, string projectName, string configuration = "Debug", string runtime = null, string framework = null) { if (projectName != null && !Path.HasExtension(projectName)) { projectName = projectName + ".csproj"; } DeleteXproj(projectDirectory); var result = new BuildCommand() .WithWorkingDirectory(projectDirectory) .WithRuntime(runtime) .WithFramework(framework) .ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}"); result .Should().Pass(); return(result.StdOut); }
public void XmlDocumentationFileIsGenerated() { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); root.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); var testLibDir = root.CreateDirectory("TestLibrary"); // copy projects to the temp dir and restore them CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); RunRestore(testLibDir.Path); // run compile var outputDir = Path.Combine(testLibDir.Path, "bin"); var testProject = GetProjectPath(testLibDir); var buildCommand = new BuildCommand(testProject, output: outputDir); var result = buildCommand.ExecuteWithCapturedOutput(); result.Should().Pass(); // verify the output xml file var outputXml = Path.Combine(outputDir, "Debug", "dnxcore50", "TestLibrary.xml"); Console.WriteLine("OUTPUT XML PATH: " + outputXml); Assert.True(File.Exists(outputXml)); Assert.Contains("Gets the message from the helper", File.ReadAllText(outputXml)); }
public void TestDotnetIncrementalBuild() { // first build var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: NetCoreAppTfm); buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput); var binariesOutputDirectory = GetCompilationOutputPath(OutputDirectory, false); var latestWriteTimeFirstBuild = GetLastWriteTimeUtcOfDirectoryFiles( binariesOutputDirectory); // second build; should get skipped (incremental because no inputs changed) buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput); var latestWriteTimeUtcSecondBuild = GetLastWriteTimeUtcOfDirectoryFiles( binariesOutputDirectory); Assert.Equal(latestWriteTimeFirstBuild, latestWriteTimeUtcSecondBuild); TouchSourceFileInDirectory(TestDirectory); // third build; should get compiled because the source file got touched buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput); var latestWriteTimeUtcThirdBuild = GetLastWriteTimeUtcOfDirectoryFiles( binariesOutputDirectory); Assert.NotEqual(latestWriteTimeUtcSecondBuild, latestWriteTimeUtcThirdBuild); }
public void TestDotnetBuild() { var buildCommand = new BuildCommand(TestProject, output: OutputDirectory); buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName()); }
public void TestDotnetBuild() { var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: NetCoreAppTfm); buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetPortableOutputName(), s_expectedOutput); }
public void TestDotnetBuild() { var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: DefaultFramework); buildCommand.Execute().Should().Pass(); TestOutputExecutable(OutputDirectory, buildCommand.GetOutputExecutableName(), s_expectedOutput); }
private void BuildProjectJson(string projectDirectory) { var projectFile = Path.Combine(projectDirectory, "project.json"); var result = new BuildCommand(projectPath: projectFile) .ExecuteWithCapturedOutput(); result.Should().Pass(); }
public void It_skips_build_when_the_no_build_flag_is_passed() { var buildCommand = new BuildCommand(_projectFilePath); var result = buildCommand.Execute(); result.Should().Pass(); var testCommand = new DotnetTestCommand(); result = testCommand.Execute($"{_projectFilePath} -o {_defaultOutputPath} --no-build"); result.Should().Pass(); }
public void Test_Build_Project_with_Resources_with_Space_in_Path_Should_Succeed() { var spaceBufferDirectory = _root.CreateDirectory("space directory"); var testAppDir = spaceBufferDirectory.CreateDirectory("TestProjectWithResource"); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestProjectWithResource"), testAppDir); var testProject = GetProjectPath(testAppDir); var buildCommand = new BuildCommand(testProject); buildCommand.Execute().Should().Pass(); }
public void BuildSingleProject(TestInstance instance) { foreach (var iteration in Benchmark.Iterations) { var buildCommand = new BuildCommand(instance.TestRoot, buildProfile: false); using (iteration.StartMeasurement()) { buildCommand.Execute().Should().Pass(); } TouchSource(instance.TestRoot); } }
private void Setup(string project, ref string projectDir, ref string buildDir, ref string publishDir) { projectDir = Path.Combine(_testInstance.TestRoot, project); buildDir = Path.Combine(projectDir, _buildRelativePath); publishDir = Path.Combine(projectDir, "publish"); var buildCommand = new BuildCommand(projectDir, framework: Framework, runtime: _Runtime); buildCommand.Execute().Should().Pass(); var publishCommand = new PublishCommand(projectDir, output: publishDir, framework: Framework, runtime: _Runtime); publishCommand.Execute().Should().Pass(); }
private DirectoryInfo Build(TestInstance testInstance) { var result = new BuildCommand( projectPath: Path.Combine(testInstance.TestRoot, "PortableApp")) .ExecuteWithCapturedOutput(); result.Should().Pass(); var outputBase = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "PortableApp", "bin", "Debug")); return outputBase.Sub("netstandard1.5"); }
public void Compilation_of_valid_app_should_succeed() { var testProject = Path.Combine(s_testProjectsRoot, "TestAppWithArgs", "project.json"); var buildCommand = new BuildCommand(testProject); var oldDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Path.GetDirectoryName(testProject)); buildCommand.Execute().Should().Pass(); Directory.SetCurrentDirectory(oldDirectory); }
public void Compilation_of_app_with_invalid_source_should_fail() { var testProject = Path.Combine(s_testProjectsRoot, "CompileFailApp", "project.json"); var buildCommand = new BuildCommand(testProject); var oldDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(Path.GetDirectoryName(testProject)); buildCommand.Execute().Should().Fail(); Directory.SetCurrentDirectory(oldDirectory); }
public void ErrorOccursWhenBuildingPortableProjectToSpecificOutputPathWithoutSpecifyingFramework() { var testInstance = TestAssetsManager.CreateTestInstance("PortableTests") .WithLockFiles(); var result = new BuildCommand( projectPath: Path.Combine(testInstance.TestRoot, "PortableApp"), output: Path.Combine(testInstance.TestRoot, "out")) .ExecuteWithCapturedOutput(); result.Should().Fail(); result.Should().HaveStdErrContaining("When the '--output' option is provided, the '--framework' option must also be provided."); }
public void ErrorOccursWhenBuildingPortableProjectAndSpecifyingFrameworkThatProjectDoesNotSupport() { var testInstance = TestAssetsManager.CreateTestInstance("PortableTests") .WithLockFiles(); var result = new BuildCommand( projectPath: Path.Combine(testInstance.TestRoot, "PortableApp"), output: Path.Combine(testInstance.TestRoot, "out"), framework: "sl40") .ExecuteWithCapturedOutput(); result.Should().Fail(); result.Should().HaveStdErrContaining("Project does not support framework: Silverlight,Version=v4.0."); }
public void It_builds_projects_with_Unicode_in_path() { var testInstance = TestAssetsManager .CreateTestInstance("TestAppWithUnicodéPath") .WithLockFiles(); var testProjectDirectory = testInstance.TestRoot; var buildCommand = new BuildCommand(""); buildCommand.WorkingDirectory = testProjectDirectory; buildCommand.ExecuteWithCapturedOutput() .Should() .Pass(); }
public void LibraryWithAnalyzer() { var root = Temp.CreateDirectory(); var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer"); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer"), testLibDir); // run compile var outputDir = Path.Combine(testLibDir.Path, "bin"); var testProject = GetProjectPath(testLibDir); var buildCmd = new BuildCommand(testProject, output: outputDir); var result = buildCmd.ExecuteWithCapturedOutput(); result.Should().Pass(); Assert.Contains("CA1018", result.StdOut); }
public void TestDotnetBuildNativeCpp() { if(IsCentOS()) { Console.WriteLine("Skipping native compilation tests on CentOS - https://github.com/dotnet/cli/issues/453"); return; } var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, native: true, nativeCppMode: true); buildCommand.Execute().Should().Pass(); var nativeOut = Path.Combine(OutputDirectory, "native"); TestOutputExecutable(nativeOut, buildCommand.GetOutputExecutableName()); }
public void MeasureDotNetBuild() { foreach (var iter in Benchmark.Iterations) { // Setup a new instance of the test project. TestInstanceSetup(); // Setup the build command. var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: DefaultFramework); using (iter.StartMeasurement()) { // Execute the build command. buildCommand.Execute(); } } }
public GivenThatWeWantToUseDotnetTestE2EInDesignTime() { var testInstance = TestAssetsManager.CreateTestInstance("ProjectWithTests").WithLockFiles(); _projectFilePath = Path.Combine(testInstance.TestRoot, "project.json"); var contexts = ProjectContext.CreateContextForEachFramework( _projectFilePath, null, PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); var runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier; _outputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultFramework, runtime); var buildCommand = new BuildCommand(_projectFilePath); var result = buildCommand.Execute(); result.Should().Pass(); }
protected CommandResult BuildProject(string projectFile, bool noDependencies = false, bool noIncremental = false, bool expectBuildFailure = false) { var buildCommand = new BuildCommand(projectFile, output: GetOutputDir(), framework: "dnxcore50", noIncremental: noIncremental, noDependencies : noDependencies); var result = buildCommand.ExecuteWithCapturedOutput(); if (!expectBuildFailure) { result.Should().Pass(); TestOutputExecutable(GetOutputExePath(), buildCommand.GetOutputExecutableName(), ExpectedOutput); } else { result.Should().Fail(); } return result; }
private string BuildMSBuild(string projectDirectory, string projectName, string configuration = "Debug") { if (projectName != null) { projectName = projectName + ".csproj"; } DeleteXproj(projectDirectory); var result = new BuildCommand() .WithWorkingDirectory(projectDirectory) .ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}"); result .Should().Pass(); return(result.StdOut); }
public void WrappedProjectFilesResolvedCorrectly() { var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithWrapperProjectDependency") .WithBuildArtifacts() .WithLockFiles(); var root = testInstance.TestRoot; // run compile var outputDir = Path.Combine(root, "bin"); var testProject = ProjectUtils.GetProjectJson(root, "TestApp"); var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework); var result = buildCommand.ExecuteWithCapturedOutput(); result.Should().Pass(); new DirectoryInfo(outputDir).Should() .HaveFiles(new [] { "TestLibrary.dll", "TestLibrary.pdb" }); }
public void TestRebuildWhenVersionSuffixChanged() { var testInstance = TestAssetsManager.CreateTestInstance("TestSimpleIncrementalApp") .WithLockFiles(); // Build with Version Suffix 1 var command = new BuildCommand(testInstance.TestRoot, versionSuffix: "1"); var result = command.ExecuteWithCapturedOutput(); // Verify the result result.Should().HaveCompiledProject("TestSimpleIncrementalApp", ".NETCoreApp,Version=v1.0"); // Build with Version Suffix 2 command = new BuildCommand(testInstance.TestRoot, versionSuffix: "2"); result = command.ExecuteWithCapturedOutput(); // Verify the result result.Should().HaveCompiledProject("TestSimpleIncrementalApp", ".NETCoreApp,Version=v1.0"); }
public GivenThatWeWantToUseDotnetTestE2EInDesignTime() { var testInstance = TestAssetsManager.CreateTestInstance(Path.Combine("ProjectsWithTests", "NetCoreAppOnlyProject")); _projectFilePath = Path.Combine(testInstance.TestRoot, "project.json"); var contexts = ProjectContext.CreateContextForEachFramework( _projectFilePath, null, RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers()); // Restore the project again in the destination to resolve projects // Since the lock file has project relative paths in it, those will be broken // unless we re-restore new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute().Should().Pass(); _outputPath = Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0"); var buildCommand = new BuildCommand(_projectFilePath); var result = buildCommand.Execute(); result.Should().Pass(); }
protected CommandResult BuildProject(bool forceIncrementalUnsafe = false, bool expectBuildFailure = false) { var outputDir = GetBinDirectory(); var intermediateOutputDir = Path.Combine(Directory.GetParent(outputDir).FullName, "obj", _mainProject); var mainProjectFile = GetProjectFile(_mainProject); var buildCommand = new BuildCommand(mainProjectFile, output: outputDir, tempOutput: intermediateOutputDir ,forceIncrementalUnsafe : forceIncrementalUnsafe); var result = buildCommand.ExecuteWithCapturedOutput(); if (!expectBuildFailure) { result.Should().Pass(); TestOutputExecutable(outputDir, buildCommand.GetOutputExecutableName(), _expectedOutput); } else { result.Should().Fail(); } return result; }
public DirectoryInfo Build(TestInstance testInstance) { var projectPath = Path.Combine(testInstance.TestRoot, "StandaloneApp"); var result = new BuildCommand( projectPath: projectPath) .ExecuteWithCapturedOutput(); var contexts = ProjectContext.CreateContextForEachFramework( projectPath, null, PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); var runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier; result.Should().Pass(); var outputBase = new DirectoryInfo( Path.Combine(testInstance.TestRoot, "StandaloneApp", "bin", "Debug", "netstandardapp1.5")); return outputBase.Sub(runtime); }