Пример #1
0
        private static (VBRuntime, string[]) GetExpectedOutputs(string targetFramework, bool isExe)
        {
            switch ((targetFramework, isExe))
            {
            case ("net45", true):
                var files = new[]
                {
                    "HelloWorld.exe",
                    "HelloWorld.exe.config",
                    "HelloWorld.pdb"
                };
                if (TestProject.ReferenceAssembliesAreInstalled(TargetDotNetFrameworkVersion.Version471))
                {
                    return(VBRuntime.Default, files);
                }
                else
                {
                    return(VBRuntime.Referenced, files);
                }

            case ("netcoreapp2.1", true):
                return(VBRuntime.Embedded, new[]
                {
                    "HelloWorld.dll",
                    "HelloWorld.pdb",
                    "HelloWorld.runtimeconfig.json",
                    "HelloWorld.runtimeconfig.dev.json",
                    "HelloWorld.deps.json",
                });

            case ("netcoreapp3.0", true):
                return(VBRuntime.Referenced, AssertionHelper.AppendApphostOnNonMacOS("HelloWorld", new[]
                {
                    "HelloWorld.dll",
                    "HelloWorld.pdb",
                    "HelloWorld.runtimeconfig.json",
                    "HelloWorld.runtimeconfig.dev.json",
                    "HelloWorld.deps.json",
                }));

            case ("netcoreapp3.0", false):
                return(VBRuntime.Referenced, new[]
                {
                    "HelloWorld.dll",
                    "HelloWorld.pdb",
                    "HelloWorld.deps.json",
                });

            case ("netstandard2.0", false):
                return(VBRuntime.Embedded, new[]
                {
                    "HelloWorld.dll",
                    "HelloWorld.pdb",
                    "HelloWorld.deps.json",
                });

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #2
0
        public void It_restores_multitargeted_net_framework_project_successfully()
        {
            var testProject = new TestProject()
            {
                Name = "ProjectWithoutTargetingPackRef",
                TargetFrameworks = "net471;net472;netcoreapp3.0",
                IsSdkProject = true,
            };

            var testAsset = _testAssetsManager.CreateTestProject(testProject);

            string projectAssetsJsonPath = Path.Combine(
                testAsset.Path,
                testProject.Name,
                "obj",
                "project.assets.json");

            var restoreCommand =
                testAsset.GetRestoreCommand(Log, relativePath: testProject.Name);
            restoreCommand.Execute().Should().Pass();

            LockFile lockFile = LockFileUtilities.GetLockFile(
                projectAssetsJsonPath,
                NullLogger.Instance);

            var net471FrameworkLibrary = lockFile.GetTarget(NuGetFramework.Parse(".NETFramework,Version=v4.7.1"), null).Libraries.FirstOrDefault((file) => file.Name.Contains("net471"));
            if (TestProject.ReferenceAssembliesAreInstalled(TargetDotNetFrameworkVersion.Version471))
            {
                net471FrameworkLibrary.Should().BeNull();
            }
            else
            {
                net471FrameworkLibrary.Name.Should().Be("Microsoft.NETFramework.ReferenceAssemblies.net471");
                net471FrameworkLibrary.Type.Should().Be("package");
            }

            var net472FrameworkLibrary = lockFile.GetTarget(NuGetFramework.Parse(".NETFramework,Version=v4.7.2"), null).Libraries.FirstOrDefault((file) => file.Name.Contains("net472"));

            if (TestProject.ReferenceAssembliesAreInstalled(TargetDotNetFrameworkVersion.Version472))
            {
                net472FrameworkLibrary.Should().BeNull();
            }
            else
            {
                net472FrameworkLibrary.Name.Should().Be("Microsoft.NETFramework.ReferenceAssemblies.net472");
                net472FrameworkLibrary.Type.Should().Be("package");
            }
        }
        public void It_fails_without_assembly_pack_reference()
        {
            var targetFramework = "net472";
            var testProject     = new TestProject()
            {
                Name             = "ProjectWithoutTargetingPackRef",
                TargetFrameworks = targetFramework,
                IsSdkProject     = true,
            };

            testProject.AdditionalProperties["AutomaticallyUseReferenceAssemblyPackages"] = "false";

            var testAsset = _testAssetsManager.CreateTestProject(testProject);

            var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));

            if (TestProject.ReferenceAssembliesAreInstalled(TargetDotNetFrameworkVersion.Version472))
            {
                buildCommand.Execute()
                .Should()
                .Pass();

                string projectAssetsJsonPath = Path.Combine(
                    testAsset.Path,
                    testProject.Name,
                    "obj",
                    "project.assets.json");
                LockFile lockFile = LockFileUtilities.GetLockFile(
                    projectAssetsJsonPath,
                    NullLogger.Instance);
                lockFile.GetTarget(NuGetFramework.Parse(".NETFramework,Version=v4.7.2"), null).Libraries.FirstOrDefault((file) => file.Name.Contains("net472"))
                .Should()
                .BeNull();
            }
            else
            {
                buildCommand.Execute()
                .Should()
                .Fail();
            }
        }
Пример #4
0
        public void It_restores_net_framework_project_successfully(string version)
        {
            var targetFrameworkVersion = (TargetDotNetFrameworkVersion)System.Enum.Parse(typeof(TargetDotNetFrameworkVersion), "Version" + string.Join("", version.Split('.')));
            var targetFramework        = "net" + string.Join("", version.Split('.'));
            var testProject            = new TestProject()
            {
                Name             = "ProjectWithoutTargetingPackRef",
                TargetFrameworks = targetFramework,
                IsSdkProject     = true,
            };

            var testAsset = _testAssetsManager.CreateTestProject(testProject);

            string projectAssetsJsonPath = Path.Combine(
                testAsset.Path,
                testProject.Name,
                "obj",
                "project.assets.json");

            var restoreCommand =
                testAsset.GetRestoreCommand(Log, relativePath: testProject.Name);

            restoreCommand.Execute().Should().Pass();

            LockFile lockFile            = LockFileUtilities.GetLockFile(projectAssetsJsonPath, NullLogger.Instance);
            var      netFrameworkLibrary = lockFile.GetTarget(NuGetFramework.Parse(".NETFramework,Version=v" + version), null).Libraries.FirstOrDefault((file) => file.Name.Contains(targetFramework));

            if (TestProject.ReferenceAssembliesAreInstalled(targetFrameworkVersion))
            {
                netFrameworkLibrary.Should().BeNull();
            }
            else
            {
                netFrameworkLibrary.Name.Should().Be("Microsoft.NETFramework.ReferenceAssemblies." + targetFramework);
                netFrameworkLibrary.Type.Should().Be("package");
            }
        }
Пример #5
0
        public void It_builds_a_simple_project(string targetFramework)
        {
            if (targetFramework == "net45" && !TestProject.ReferenceAssembliesAreInstalled("v4.5"))
            {
                // skip net45 when we do not have .NET Framework 4.5 reference assemblies
                // due to https://github.com/dotnet/core-sdk/issues/3228
                return;
            }

            var(expectedVBRuntime, expectedOutputFiles) = GetExpectedOutputs(targetFramework);

            var testProject = new TestProject
            {
                Name                 = "HelloWorld",
                IsSdkProject         = true,
                TargetFrameworks     = targetFramework,
                IsExe                = targetFramework != "netstandard2.0",
                AdditionalProperties =
                {
                    ["MyType"] = "Console",
                },
                SourceFiles =
                {
                    ["Program.vb"] = @"
                        Imports System

                        Module Program
                            Function MyComputerName() As String
                                #If NETFRAMEWORK Or NETCOREAPP3_0 Then
                                    Return My.Computer.Name
                                #End If
                            End Function

                            Sub Main(args As String())
                                Console.WriteLine(""Hello World from "" & MyComputerName())
                            End Sub
                        End Module
                        ",
                }
            };

            var testAsset = _testAssetsManager
                            .CreateTestProject(testProject, identifier: targetFramework, targetExtension: ".vbproj")
                            .Restore(Log, testProject.Name);

            var buildCommand = new GetValuesCommand(
                Log,
                Path.Combine(testAsset.TestRoot, testProject.Name),
                targetFramework,
                "VBRuntime")
            {
                DependsOnTargets = "Build"
            };

            buildCommand
            .Execute()
            .Should()
            .Pass();

            var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);
            var actualVBRuntime = GetVBRuntime(buildCommand.GetValues().FirstOrDefault());

            File.Delete(outputDirectory.File("VBRuntimeValues.txt").FullName);

            outputDirectory.Should().OnlyHaveFiles(expectedOutputFiles);
            actualVBRuntime.Should().Be(expectedVBRuntime);
        }
Пример #6
0
        public void It_restores_multitargeted_net_framework_project_successfully(bool includeExplicitReference)
        {
            var testProject = new TestProject()
            {
                Name             = "ProjectWithoutTargetingPackRef",
                TargetFrameworks = "net471;net472;netcoreapp3.0",
            };

            TestAsset testAsset = null;

            if (includeExplicitReference)
            {
                // Add explicit reference to assembly packs
                testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: includeExplicitReference.ToString()).WithProjectChanges(project =>
                {
                    var ns        = project.Root.Name.Namespace;
                    var itemGroup = project.Root.Elements(ns + "ItemGroup").FirstOrDefault();
                    itemGroup.Add(new XElement(ns + "PackageReference",
                                               new XAttribute("Include", $"Microsoft.NETFramework.ReferenceAssemblies"),
                                               new XAttribute("Version", $"1.0.0-preview.2")));
                });
            }
            else
            {
                testAsset = _testAssetsManager.CreateTestProject(testProject);
            }

            string projectAssetsJsonPath = Path.Combine(
                testAsset.Path,
                testProject.Name,
                "obj",
                "project.assets.json");

            var restoreCommand = testAsset.GetRestoreCommand(Log, relativePath: testProject.Name);

            restoreCommand.Execute()
            .Should()
            .Pass()
            .And
            .NotHaveStdOutContaining("NETSDK1023");

            LockFile lockFile = LockFileUtilities.GetLockFile(
                projectAssetsJsonPath,
                NullLogger.Instance);

            var net471FrameworkLibrary = lockFile.GetTarget(NuGetFramework.Parse(".NETFramework,Version=v4.7.1"), null).Libraries.FirstOrDefault((file) => file.Name.Contains("net471"));

            if (TestProject.ReferenceAssembliesAreInstalled(TargetDotNetFrameworkVersion.Version471) && !includeExplicitReference)
            {
                net471FrameworkLibrary.Should().BeNull();
            }
            else
            {
                net471FrameworkLibrary.Name.Should().Be("Microsoft.NETFramework.ReferenceAssemblies.net471");
                net471FrameworkLibrary.Type.Should().Be("package");
            }

            var net472FrameworkLibrary = lockFile.GetTarget(NuGetFramework.Parse(".NETFramework,Version=v4.7.2"), null).Libraries.FirstOrDefault((file) => file.Name.Contains("net472"));

            if (TestProject.ReferenceAssembliesAreInstalled(TargetDotNetFrameworkVersion.Version472) && !includeExplicitReference)
            {
                net472FrameworkLibrary.Should().BeNull();
            }
            else
            {
                net472FrameworkLibrary.Name.Should().Be("Microsoft.NETFramework.ReferenceAssemblies.net472");
                net472FrameworkLibrary.Type.Should().Be("package");
            }
        }