Exemple #1
0
        public void TestPerfLogDirectoryDoesNotExist()
        {
            using (TestEnvironment testEnv = TestEnvironment.Create(_output))
            {
                // Setup invalid perf log directory.
                TransientTestFolder perfLogFolder = testEnv.CreateFolder(createFolder: true);
                string perfLogPath = Path.Combine(perfLogFolder.Path, "logs");
                testEnv.SetEnvironmentVariable("DOTNET_PERFLOG_DIR", perfLogPath);

                // Setup project directory.
                TransientTestFolder projectFolder = testEnv.CreateFolder(createFolder: true);
                TransientTestFile   classLibrary  = testEnv.CreateFile(projectFolder, "ClassLibrary.csproj",
                                                                       @"<Project>
                  <Target Name=""ClassLibraryTarget"">
                      <Message Text=""ClassLibraryBuilt""/>
                  </Target>
                  </Project>
                    ");

                string projectPath       = Path.Combine(projectFolder.Path, "ClassLibrary.csproj");
                string msbuildParameters = "\"" + projectPath + "\"";

                Directory.Exists(perfLogPath).ShouldBeFalse();

                RunnerUtilities.ExecMSBuild(msbuildParameters, out bool successfulExit);
                successfulExit.ShouldBeTrue();

                Directory.Exists(perfLogPath).ShouldBeFalse();
            }
        }
Exemple #2
0
        private void RunMSBuildOnProjectWithPortableTaskAndAssertOutput(bool useDesktopMSBuild)
        {
            using (TestEnvironment env = TestEnvironment.Create(_outputHelper))
            {
                bool successfulExit;

                var folder   = env.CreateFolder().FolderPath;
                var projFile = Path.Combine(folder, ProjectFileName);

                foreach (var file in new DirectoryInfo(ProjectFilePath).GetFiles())
                {
                    File.Copy(file.FullName, Path.Combine(folder, file.Name));
                    _outputHelper.WriteLine($"Copied {file.FullName} to {Path.Combine(folder, file.Name)}");
                }

                File.Exists(projFile).ShouldBeTrue($"Project file {projFile} does not exist");

                _outputHelper.WriteLine(File.ReadAllText(projFile));

                _outputHelper.WriteLine($"Building project {projFile}");

                var executionOutput = useDesktopMSBuild
                    ? RunnerUtilities.RunProcessAndGetOutput("msbuild", projFile, out successfulExit,
                                                             shellExecute: true, outputHelper: _outputHelper)
                    : RunnerUtilities.ExecMSBuild(projFile, out successfulExit);

                _outputHelper.WriteLine(executionOutput);

                successfulExit.ShouldBeTrue(
                    $"{(useDesktopMSBuild ? "Desktop MSBuild" : "Non Desktop MSBuild")} failed to execute the portable task");

                Regex.Matches(executionOutput, @"Microsoft\.Build\.(\w+\.)+dll").Count.ShouldBeGreaterThan(1);
            }
        }
Exemple #3
0
        [Trait("Category", "mono-osx-failing")] // Disable on Mono OSX, since Mono doesn't implement EventSource.
        public void TestPerfLogEnabledProducedLogFile()
        {
            using (TestEnvironment testEnv = TestEnvironment.Create(_output))
            {
                // Setup perf log.
                TransientTestFolder perfLogFolder = testEnv.CreateFolder(createFolder: true);
                testEnv.SetEnvironmentVariable("DOTNET_PERFLOG_DIR", perfLogFolder.Path);

                // Setup project directory.
                TransientTestFolder projectFolder = testEnv.CreateFolder(createFolder: true);
                TransientTestFile   classLibrary  = testEnv.CreateFile(projectFolder, "ClassLibrary.csproj",
                                                                       @"<Project>
                  <Target Name=""ClassLibraryTarget"">
                      <Message Text=""ClassLibraryBuilt""/>
                  </Target>
                  </Project>
                    ");

                string projectPath       = Path.Combine(projectFolder.Path, "ClassLibrary.csproj");
                string msbuildParameters = "\"" + projectPath + "\"";

                RunnerUtilities.ExecMSBuild(msbuildParameters, out bool successfulExit);
                successfulExit.ShouldBeTrue();

                // Look for the file.
                // NOTE: We don't explicitly look for one file because it's possible that more components will add files that will show up here.
                // It's most important to ensure that at least one file shows up because any others that show up will be there because MSBuild properly
                // enabled this functionality.
                string[] files = Directory.GetFiles(perfLogFolder.Path, "perf-*.log");
                files.ShouldNotBeEmpty();
                files.ShouldAllBe(f => new FileInfo(f).Length > 0);
            }
        }
Exemple #4
0
        public void TestOldNuget()
        {
            string msbuildExePath = Path.GetDirectoryName(RunnerUtilities.PathToCurrentlyRunningMsBuildExe);

            using TestEnvironment testEnvironment = TestEnvironment.Create();
            TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: true);
            // The content of the solution isn't known to matter, but having a custom solution makes it easier to add requirements should they become evident.
            TransientTestFile sln = testEnvironment.CreateFile(folder, "test.sln",
                                                               @"
Microsoft Visual Studio Solution File, Format Version 12.00
\# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
	Debug|Any CPU = Debug|Any CPU
	Debug|x64 = Debug|x64
	Debug|x86 = Debug|x86
	Release|Any CPU = Release|Any CPU
	Release|x64 = Release|x64
	Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
	HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
");

            RunnerUtilities.RunProcessAndGetOutput(Path.Combine(msbuildExePath, "nuget", "NuGet.exe"), "restore " + sln.Path + " -MSBuildPath \"" + msbuildExePath + "\"", out bool success, outputHelper: _output);
            success.ShouldBeTrue();
        }
        public void LoadInsideAsssembly()
        {
            bool   successfulExit;
            string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag", out successfulExit);

            Assert.True(successfulExit);

            CheckIfCorrectAssemblyLoaded(output, OriginalDllPath);
        }
        public void LoadAssemblyAndDependency_InsideProjectFolder()
        {
            bool   successfulExit;
            string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag", out successfulExit);

            Assert.True(successfulExit);

            CheckIfCorrectAssemblyLoaded(output, OriginalTaskDllPath);
        }
        public void LoadNonExistingAssembly()
        {
            string dllName = "NonExistent.dll";

            bool   successfulExit;
            string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag /p:AssemblyPath=" + dllName, out successfulExit);

            Assert.False(successfulExit);

            string dllPath = Path.Combine(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, dllName);

            CheckIfCorrectAssemblyLoaded(output, dllPath, false);
        }
Exemple #8
0
        public void LoadInsideAsssembly()
        {
            using (var dir = new FileUtilities.TempWorkingDirectory(ProjectFileFolder))
            {
                string projectFilePath = Path.Combine(dir.Path, ProjectFileName);

                bool   successfulExit;
                string output = RunnerUtilities.ExecMSBuild(projectFilePath + " /v:diag", out successfulExit);
                Assert.True(successfulExit);

                string dllPath = Path.Combine(dir.Path, DLLFileName);

                CheckIfCorrectAssemblyLoaded(output, dllPath);
            }
        }
        public void LoadAssemblyAndDependency_InsideProjectFolder()
        {
            using (var dir = new FileUtilities.TempWorkingDirectory(ProjectFileFolder))
            {
                string projectFilePath = Path.Combine(dir.Path, ProjectFileName);

                bool   successfulExit;
                string output = RunnerUtilities.ExecMSBuild(projectFilePath + " /v:diag", out successfulExit);
                successfulExit.ShouldBeTrue(output);

                string dllPath = Path.Combine(dir.Path, TaskDllFileName);

                CheckIfCorrectAssemblyLoaded(output, dllPath);
            }
        }
        public void LoadAssemblyAndDependency_OutsideProjectFolder()
        {
            using (var dir = new FileUtilities.TempWorkingDirectory(ProjectFileFolder))
            {
                string projectFilePath = Path.Combine(dir.Path, ProjectFileName);

                string tempDir        = MoveOrCopyDllsToTempDir(dir.Path, copy: false);
                var    newTaskDllPath = Path.Combine(tempDir, TaskDllFileName);

                bool   successfulExit;
                string output = RunnerUtilities.ExecMSBuild(projectFilePath + " /v:diag /p:AssemblyPath=" + newTaskDllPath, out successfulExit);
                successfulExit.ShouldBeTrue(output);

                CheckIfCorrectAssemblyLoaded(output, newTaskDllPath);
            }
        }
Exemple #11
0
        private static void RunMSBuildOnProjectWithPortableTaskAndAssertOutput(bool useDesktopMSBuild)
        {
            bool   successfulExit;
            string executionOutput;

            Assert.True(File.Exists(ProjectFilePath), $"Project file {ProjectFilePath} does not exist");

            executionOutput = useDesktopMSBuild ?
                              RunnerUtilities.RunProcessAndGetOutput("msbuild", ProjectFilePath, out successfulExit, shellExecute: true) :
                              RunnerUtilities.ExecMSBuild(ProjectFilePath, out successfulExit);

            Assert.True(successfulExit, $"{(useDesktopMSBuild ? "Desktop MSBuild" : "Non Desktop MSBuild")} failed to execute the portable task");

            var matches = Regex.Matches(executionOutput, @"Microsoft\.Build\.(\w+\.)+dll");

            Assert.True(matches.Count > 1);
        }
Exemple #12
0
        public void LoadNonExistingAssembly()
        {
            using var dir = new FileUtilities.TempWorkingDirectory(ProjectFileFolder);

            string projectFilePath = Path.Combine(dir.Path, ProjectFileName);

            string dllName = "NonExistent.dll";

            bool   successfulExit;
            string output = RunnerUtilities.ExecMSBuild(projectFilePath + " /v:diag /p:AssemblyPath=" + dllName, out successfulExit, _output);

            successfulExit.ShouldBeFalse();

            string dllPath = Path.Combine(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory, dllName);

            CheckIfCorrectAssemblyLoaded(output, dllPath, false);
        }
Exemple #13
0
        public void LoadInsideAssemblyWhenGivenOutsideAssemblyWithSameName()
        {
            string copiedDllPath = MoveOrCopyDllToTempDir(copy: true);

            try
            {
                bool   successfulExit;
                string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag /p:AssemblyPath=" + copiedDllPath, out successfulExit);
                Assert.True(successfulExit);

                CheckIfCorrectAssemblyLoaded(output, OriginalDllPath);
            }
            finally
            {
                UndoDLLOperations(copiedDllPath, moveBack: false);
            }
        }
Exemple #14
0
        public void LoadOutsideAssembly()
        {
            string movedDLLPath = MoveOrCopyDllToTempDir(copy: false);

            try
            {
                bool   successfulExit;
                string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag /p:AssemblyPath=" + movedDLLPath, out successfulExit);
                Assert.True(successfulExit);

                CheckIfCorrectAssemblyLoaded(output, movedDLLPath);
            }
            finally
            {
                UndoDLLOperations(movedDLLPath, moveBack: true);
            }
        }
        public void LoadAssemblyAndDependency_OutsideProjectFolder()
        {
            string tempDir        = MoveOrCopyDllsToTempDir(copy: false);
            var    newTaskDllPath = Path.Combine(tempDir, TaskDllFileName);

            try
            {
                bool   successfulExit;
                string output = RunnerUtilities.ExecMSBuild(ProjectFilePath + " /v:diag /p:AssemblyPath=" + newTaskDllPath, out successfulExit);
                Assert.True(successfulExit);

                CheckIfCorrectAssemblyLoaded(output, newTaskDllPath);
            }
            finally
            {
                UndoDLLOperations(tempDir, moveBack: true);
            }
        }
Exemple #16
0
        public void LoadInsideAssemblyWhenGivenOutsideAssemblyWithSameName()
        {
            using (var dir = new FileUtilities.TempWorkingDirectory(ProjectFileFolder))
            {
                string projectFilePath = Path.Combine(dir.Path, ProjectFileName);
                string originalDLLPath = Path.Combine(dir.Path, DLLFileName);
                string copiedDllPath   = MoveOrCopyDllToTempDir(originalDLLPath, copy: true);

                try
                {
                    bool   successfulExit;
                    string output = RunnerUtilities.ExecMSBuild(projectFilePath + " /v:diag /p:AssemblyPath=" + copiedDllPath, out successfulExit);
                    Assert.True(successfulExit);

                    CheckIfCorrectAssemblyLoaded(output, originalDLLPath);
                }
                finally
                {
                    UndoDLLOperations(copiedDllPath);
                }
            }
        }
        public void InlineTaskWithAssemblyPlatformAgnostic()
        {
            using (TestEnvironment env = TestEnvironment.Create())
            {
                TransientTestFolder folder   = env.CreateFolder(createFolder: true);
                string            location   = Assembly.GetExecutingAssembly().Location;
                TransientTestFile inlineTask = env.CreateFile(folder, "5106.proj", @$ "
<Project>

  <UsingTask TaskName=" "MyInlineTask" " TaskFactory=" "RoslynCodeTaskFactory" " AssemblyFile=" "$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" ">
    <Task>
      <Reference Include=" "" + Path.Combine(Path.GetDirectoryName(location), "..", "..", "..", "Samples", "Dependency",
#if DEBUG
                                             "Debug"
#else
                                             "Release"
#endif
                                             , "net472", "Dependency.dll") + @""" />
      <Using Namespace=""Dependency"" />
      <Code Type=""Fragment"" Language=""cs"" >
<![CDATA[
Log.LogError(Alpha.GetString());
]]>
      </Code>
    </Task>
  </UsingTask>

<Target Name=""ToRun"">
  <MyInlineTask/>
</Target>

</Project>
");
                string output = RunnerUtilities.ExecMSBuild(inlineTask.Path, out bool success);
                success.ShouldBeTrue(output);
                output.ShouldContain("Alpha.GetString");
            }
        }