Exemplo n.º 1
0
        public void SingleProject()
        {
            Dictionary <string, string> globalProperties = new Dictionary <string, string>
            {
                [MSBuildPropertyNames.DesignTimeBuild]          = bool.TrueString,
                [MSBuildPropertyNames.SlnGenLaunchVisualStudio] = bool.FalseString,
            };

            ProjectCollection projectCollection = new ProjectCollection(globalProperties);

            ProjectCreator
            .Create(Path.Combine(TestRootPath, "Directory.Build.props"))
            .Save();
            ProjectCreator
            .Create(Path.Combine(TestRootPath, "Directory.Build.targets"))
            .Property("SlnGenAssemblyFile", Path.Combine(Environment.CurrentDirectory, "slngen.exe"))
            .Import(Path.Combine(Environment.CurrentDirectory, "build", "Microsoft.VisualStudio.SlnGen.targets"), condition: "'$(IsCrossTargetingBuild)' != 'true'")
            .Import(Path.Combine(Environment.CurrentDirectory, "buildMultiTargeting", "Microsoft.VisualStudio.SlnGen.targets"), condition: "'$(IsCrossTargetingBuild)' == 'true'")
            .Save();

            ProjectCreator project = ProjectCreator.Templates
                                     .SdkCsproj(
                Path.Combine(TestRootPath, "ProjectA", "ProjectA.csproj"),
                targetFramework: "netcoreapp2.0",
                projectCollection: projectCollection)
                                     .Save()
                                     .TryBuild("SlnGen", out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs);

            result.ShouldBeTrue(buildOutput.GetConsoleLog());

            KeyValuePair <string, TargetResult> targetOutput = targetOutputs.ShouldHaveSingleItem();

            targetOutput.Key.ShouldBe("SlnGen");

            FileInfo expected = new FileInfo(Path.Combine(Path.ChangeExtension(project.FullPath, ".sln")));

            expected.Exists.ShouldBeTrue();

            SolutionFile solutionFile = SolutionFile.Parse(expected.FullName);

            solutionFile.SolutionConfigurations
            .Select(i => i.FullName)
            .ShouldBe(new[]
            {
                "Debug|Any CPU",
                "Release|Any CPU",
            });

            solutionFile.ProjectsInOrder
            .Select(i => i.AbsolutePath)
            .ShouldBe(new[]
            {
                project.FullPath,
            });
        }
Exemplo n.º 2
0
        public void ItemGroupCondition()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .ItemGroup(condition: "4AEF424E1AFB46DF844A29AC9663329E")
            .Xml
            .ShouldBe(
                @"<Project>
  <ItemGroup Condition=""4AEF424E1AFB46DF844A29AC9663329E"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 3
0
        public void ItemGroupSimple()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .ItemGroup()
            .Xml
            .ShouldBe(
                @"<Project>
  <ItemGroup />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 4
0
        public void UsingTaskAssemblyFileSimple()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .UsingTaskAssemblyFile("BCC53601667C4195A9DCDCEF59C4C0F0", "125F7786CD46409FA09B4999629BAF4F")
            .Xml
            .ShouldBe(
                @"<Project>
  <UsingTask TaskName=""BCC53601667C4195A9DCDCEF59C4C0F0"" AssemblyFile=""125F7786CD46409FA09B4999629BAF4F"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 5
0
        public void SdkWithVersion()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Sdk("9104FA3137FB4581B337262DCBDBAD6A", "AA99A15EABF84EB2A6F23A9495A1D160")
            .Xml
            .ShouldBe(
                @"<Project>
  <Sdk Name=""9104FA3137FB4581B337262DCBDBAD6A"" Version=""AA99A15EABF84EB2A6F23A9495A1D160"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 6
0
        public void ImportSdkTest()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .ImportSdk("B8E5AE4F7DBF4688B0A3F0E07C73FDE2", "BF3306138DB942BDB330230D07A2A8AD", version: "5D31D10637474DE3ADE35AF5236D7D6B", condition: "4A4274FD1456435EB6D059F91A8C279B")
            .Xml
            .ShouldBe(
                @"<Project>
  <Import Project=""B8E5AE4F7DBF4688B0A3F0E07C73FDE2"" Condition=""4A4274FD1456435EB6D059F91A8C279B"" Sdk=""BF3306138DB942BDB330230D07A2A8AD"" Version=""5D31D10637474DE3ADE35AF5236D7D6B"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 7
0
        public void ImportSimple()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import("78885C0A95004569B281C097FE6A8252")
            .Xml
            .ShouldBe(
                @"<Project>
  <Import Project=""78885C0A95004569B281C097FE6A8252"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 8
0
        public void ImportWithCondition()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import("01C2CD160C4C4D3A81543D1003C3D750", condition: "541AB4AD8EE747818A54385CED55A50A")
            .Xml
            .ShouldBe(
                @"<Project>
  <Import Project=""01C2CD160C4C4D3A81543D1003C3D750"" Condition=""541AB4AD8EE747818A54385CED55A50A"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 9
0
        public void ImportSdk()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import("6D75CC8EE2FA40AA8A0DC43112A85A0C", sdk: "4E45E3BD92B941338162B69846B462AE")
            .Xml
            .ShouldBe(
                @"<Project>
  <Import Project=""6D75CC8EE2FA40AA8A0DC43112A85A0C"" Sdk=""4E45E3BD92B941338162B69846B462AE"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 10
0
        public void ImportWithConditionOnExistence()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import("150D2AEC5CA24ADEBB6A6FDBDE4AA26D", condition: "42649D00AF3644A1A23FACDC111F85D8", conditionOnExistence: true)
            .Xml
            .ShouldBe(
                @"<Project>
  <Import Project=""150D2AEC5CA24ADEBB6A6FDBDE4AA26D"" Condition=""Exists('150D2AEC5CA24ADEBB6A6FDBDE4AA26D')"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 11
0
        public void CustomExtensionMethod()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .ForTestingOnly("4FCA06D98CEC4250B5E34FA66A85282B", "FAA8493986E442888CE8652BD7622B2C")
            .Xml
            .ShouldBe(
                @"<Project>
  <Import Project=""4FCA06D98CEC4250B5E34FA66A85282B"" Condition=""FAA8493986E442888CE8652BD7622B2C"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 12
0
        public void TryGetPropertyValueSimple()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Property("E7A39154F5AB476A928067251F88FFCE", "E8F579A7E3374F389120CF6D888E74B9")
            .Property("FAB58E5B32D14990ACE2490D7593FDF6", "60F55FB14D2E44B2BA4EC91488D9FF8F")
            .TryGetPropertyValue("E7A39154F5AB476A928067251F88FFCE", out string property1)
            .TryGetPropertyValue("FAB58E5B32D14990ACE2490D7593FDF6", out string property2);

            property1.ShouldBe("E8F579A7E3374F389120CF6D888E74B9");
            property2.ShouldBe("60F55FB14D2E44B2BA4EC91488D9FF8F");
        }
Exemplo n.º 13
0
        public void ImportSdkAndVersion()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import("8F66583869B84CE89D72FF6DAC8A3C66", sdk: "8E35FA0BABDB4488AA096CCF6C82C37A", sdkVersion: "E8835BFC0CF949BFB63AB3917294C41A")
            .Xml
            .ShouldBe(
                @"<Project>
  <Import Project=""8F66583869B84CE89D72FF6DAC8A3C66"" Sdk=""8E35FA0BABDB4488AA096CCF6C82C37A"" Version=""E8835BFC0CF949BFB63AB3917294C41A"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 14
0
        public void SdkSimple()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Sdk("8CFA5E8611DB4F12963FF495C43E015D")
            .Xml
            .ShouldBe(
                @"<Project>
  <Sdk Name=""8CFA5E8611DB4F12963FF495C43E015D"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 15
0
        public void ProjectIsReEvaluated()
        {
            ProjectCollection projectCollection = new ProjectCollection();

            ProjectCreator creator = ProjectCreator.Create(projectCollection: projectCollection);

            creator.Project.GetPropertyValue("Property1").ShouldBe(string.Empty);

            creator.Project.SetGlobalProperty("Property1", "8AD6F0530E774E468DBBD5B4143A1B1D");

            creator.Project.GetPropertyValue("Property1").ShouldBe("8AD6F0530E774E468DBBD5B4143A1B1D");
        }
Exemplo n.º 16
0
        public async Task BuildShouldUseDotNetCertifcateIfSetWithPostBuildSigning(bool?useDotNetCert)
        {
            var envVars = Environment.GetEnvironmentVariables();

            using (var builder = new TestRepoBuilder(nameof(BuildShouldUseDotNetCertifcateIfSet), _commonRepoResourcesFixture.CommonResources))
            {
                await builder.AddDefaultRepoSetupAsync();

                // Always put in the AllowEmptySignList
                var signingProps = ProjectCreator.Create().PropertyGroup();
                signingProps.Property("AllowEmptySignList", "true");

                if (useDotNetCert.HasValue)
                {
                    signingProps.Property("UseDotNetCertificate", useDotNetCert.Value.ToString());
                }

                builder.AddProject(signingProps, "eng/Signing.props");

                // Create a simple project
                builder.AddProject(ProjectCreator
                                   .Templates
                                   .SdkCsproj(
                                       targetFramework: "net6.0",
                                       outputType: "Exe")
                                   .PropertyGroup()
                                   .Property("IsPackable", "true")
                                   .Property("EnableSourceLink", "false"),
                                   "./src/FooPackage/FooPackage.csproj");
                await builder.AddSimpleCSFile("src/FooPackage/Program.cs");

                builder.Build(
                    TestRepoUtils.BuildArg("configuration"),
                    "Release",
                    TestRepoUtils.BuildArg("restore"),
                    TestRepoUtils.BuildArg("pack"),
                    TestRepoUtils.BuildArg("publish"),
                    TestRepoUtils.BuildArg("sign"),
                    TestRepoUtils.BuildArg("projects"),
                    Path.Combine(builder.TestRepoRoot, "src/FooPackage/FooPackage.csproj"),
                    "/p:AutoGenerateSymbolPackages=false",
                    "/p:PostBuildSign=true",
                    "/p:DotNetPublishUsingPipelines=true")
                .Should().NotThrow();
                string assetManifestText = GetAssetManifest(builder);
                string expectedCert      = useDotNetCert.GetValueOrDefault() ? DotNetCertificate : MicrosoftCertificate;
                string unexpectedCert    = useDotNetCert.GetValueOrDefault() ? MicrosoftCertificate : DotNetCertificate;

                // Ensure that we see the expected cert.
                assetManifestText.IndexOf(unexpectedCert).Should().Be(-1);
                assetManifestText.IndexOf(expectedCert).Should().NotBe(-1);
            }
        }
Exemplo n.º 17
0
        public void ImportProjectRootElement()
        {
            ProjectCreator project1 = ProjectCreator.Create("24775F0E17A348979DB4DF3D357621F9");

            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import(project1.RootElement, condition: "5884085731AB4A588AC8337069C3223B")
            .Xml
            .ShouldBe(
                $@"<Project>
  <Import Project=""{project1.FullPath}"" Condition=""5884085731AB4A588AC8337069C3223B"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 18
0
        public void ImportProjectCreator()
        {
            ProjectCreator project1 = ProjectCreator.Create("A4DD67D773834B24AC6AEA317653AD28");

            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import(project1, condition: "E4E4F3ECECF444D28D65F5A59D4B2E89")
            .Xml
            .ShouldBe(
                $@"<Project>
  <Import Project=""{project1.FullPath}"" Condition=""E4E4F3ECECF444D28D65F5A59D4B2E89"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 19
0
        public void ImportProject()
        {
            ProjectCreator project1 = ProjectCreator.Create("B2EE38CD5D1E4B228655A95B2B7224BA");

            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Import(project1.Project, condition: "8D9C051BE69C4EB99B7C4A53C80A625D")
            .Xml
            .ShouldBe(
                $@"<Project>
  <Import Project=""{project1.FullPath}"" Condition=""8D9C051BE69C4EB99B7C4A53C80A625D"" />
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 20
0
        public void PropertySetIfEmpty()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Property("A47F78111F084710B139CD5AEEB5395E", string.Empty)
            .Xml
            .ShouldBe(
                @"<Project>
  <PropertyGroup>
    <A47F78111F084710B139CD5AEEB5395E />
  </PropertyGroup>
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 21
0
        public void ContentItem()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .ItemContent("2B63E02B870E4F2FBE812995C081B0C5")
            .Xml
            .ShouldBe(
                @"<Project>
  <ItemGroup>
    <Content Include=""2B63E02B870E4F2FBE812995C081B0C5"" />
  </ItemGroup>
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 22
0
        public void TryGetItemsCustomSelector()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .ItemInclude("MyItem", "3F114C1509CF4D499A44F986BEBD5707")
            .ItemInclude("MyItem", "8A9654A639F5429AB1C7A8F2AE9639D8")
            .TryGetItems("MyItem", i => i.EvaluatedInclude, out IReadOnlyCollection <string> items);

            items.ShouldBe(new List <string>
            {
                "3F114C1509CF4D499A44F986BEBD5707",
                "8A9654A639F5429AB1C7A8F2AE9639D8",
            });
        }
Exemplo n.º 23
0
        private static void ValidateParseCustomProjectTypeGuids(string fileExtension, string projectTypeGuid, string expectedFileExtension, Guid expectedProjectTypeGuid)
        {
            Project project = ProjectCreator.Create()
                              .ItemInclude(
                MSBuildItemNames.SlnGenCustomProjectTypeGuid,
                fileExtension,
                metadata: new Dictionary <string, string>
            {
                { MSBuildPropertyNames.ProjectTypeGuid, projectTypeGuid },
            });

            ValidateParseCustomProjectTypeGuids(project, expectedFileExtension, expectedProjectTypeGuid);
        }
Exemplo n.º 24
0
        public void PropertySimple()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Property("FF38992245B549C5B353B1662A7A330D", "60B667098861411CA81AD8A8A355A649")
            .Xml
            .ShouldBe(
                @"<Project>
  <PropertyGroup>
    <FF38992245B549C5B353B1662A7A330D>60B667098861411CA81AD8A8A355A649</FF38992245B549C5B353B1662A7A330D>
  </PropertyGroup>
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 25
0
        public void RestoreTargetCanBeRun()
        {
            ProjectCreator
            .Create(Path.Combine(TestRootPath, "project1.proj"))
            .Target("Restore")
            .TaskMessage("312D2E6ABDDC4735B437A016CED1A68E", MessageImportance.High, condition: "'$(MSBuildRestoreSessionId)' != ''")
            .TaskError("MSBuildRestoreSessionId was not defined", condition: "'$(MSBuildRestoreSessionId)' == ''")
            .TryRestore(out bool result, out BuildOutput buildOutput);

            result.ShouldBeTrue(buildOutput.GetConsoleLog());

            buildOutput.MessageEvents.High.ShouldContain(i => i.Message == "312D2E6ABDDC4735B437A016CED1A68E" && i.Importance == MessageImportance.High, buildOutput.GetConsoleLog());
        }
Exemplo n.º 26
0
        public void TaskSimple()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Task("CAD7EC3FFA634946996F92FA823E3A9D")
            .Xml
            .ShouldBe(
                $@"<Project>
  <Target Name=""{ProjectCreatorConstants.DefaultTargetName}"">
    <CAD7EC3FFA634946996F92FA823E3A9D />
  </Target>
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 27
0
        public void BuildOutputIsComplete()
        {
            ProjectCreator.Create()
            .Target("Build")
            .For(100, (i, creator) => creator.TaskMessage($"Message {i}", MessageImportance.High))
            .TryBuild(out bool result, out BuildOutput buildOutput);

            result.ShouldBeTrue(buildOutput.GetConsoleLog());

            buildOutput.IsShutdown.ShouldBeTrue();

            buildOutput.MessageEvents.High.Count.ShouldBe(100, buildOutput.GetConsoleLog());
        }
Exemplo n.º 28
0
        public async Task BuildShouldErrorIfNoItemsToSignAndNonEmptySignPostBuildList(bool propertyIsSet)
        {
            var envVars = Environment.GetEnvironmentVariables();

            using (var builder = new TestRepoBuilder(nameof(BuildShouldErrorIfNoItemsToSignAndNonEmptySignPostBuildList), _commonRepoResourcesFixture.CommonResources))
            {
                await builder.AddDefaultRepoSetupAsync();

                // Always put in the AllowEmptySignList
                var signingProps = ProjectCreator.Create().PropertyGroup();
                signingProps.Property("AllowEmptySignList", "true");

                if (propertyIsSet)
                {
                    signingProps.Property("AllowEmptySignPostBuildList", "false");
                }

                // Clear out ItemsToSignPostBuild
                signingProps.ItemGroup()
                .ItemRemove("ItemsToSignPostBuild", "@(ItemsToSignPostBuild)");

                builder.AddProject(signingProps, "eng/Signing.props");

                // Create a simple project
                builder.AddProject(ProjectCreator
                                   .Templates
                                   .SdkCsproj(
                                       targetFramework: "net6.0",
                                       outputType: "Exe")
                                   .PropertyGroup()
                                   .Property("IsPackable", "true")
                                   .Property("EnableSourceLink", "false"),
                                   "./src/FooPackage/FooPackage.csproj");
                await builder.AddSimpleCSFile("src/FooPackage/Program.cs");

                builder.Build(
                    TestRepoUtils.BuildArg("configuration"),
                    "Release",
                    TestRepoUtils.BuildArg("restore"),
                    TestRepoUtils.BuildArg("pack"),
                    TestRepoUtils.BuildArg("publish"),
                    TestRepoUtils.BuildArg("sign"),
                    TestRepoUtils.BuildArg("projects"),
                    Path.Combine(builder.TestRepoRoot, "src/FooPackage/FooPackage.csproj"),
                    "/p:AutoGenerateSymbolPackages=false",
                    "/p:PostBuildSign=true")
                .Should().Throw <Exception>($"build of repo {builder.TestRepoRoot} is post build signed")
                .WithMessage("*error : List of files to sign post-build is empty. Make sure that ItemsToSignPostBuild is configured correctly.*");
            }
        }
Exemplo n.º 29
0
        public void PropertyNotSetIfNull()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .Property("BFB895A7AD3F4CAFBE514DCFE5D30354", null)
            .Property("B712A0D4A328439E8862D6715E044AB7", "2C9E4222FEBF43F7B841099EC3DDB14B")
            .Xml
            .ShouldBe(
                @"<Project>
  <PropertyGroup>
    <B712A0D4A328439E8862D6715E044AB7>2C9E4222FEBF43F7B841099EC3DDB14B</B712A0D4A328439E8862D6715E044AB7>
  </PropertyGroup>
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }
Exemplo n.º 30
0
        public void ItemIncludeNotAddedIfNull()
        {
            ProjectCreator.Create(projectFileOptions: NewProjectFileOptions.None)
            .ItemInclude("D7DAD38333D04A5999F9791575DBB57D", null)
            .ItemInclude("FDA04096ED074663997F13D37E81E87A", "CBCFA7D42A3B4A1B93127FAFA13CD3DB")
            .Xml
            .ShouldBe(
                @"<Project>
  <ItemGroup>
    <FDA04096ED074663997F13D37E81E87A Include=""CBCFA7D42A3B4A1B93127FAFA13CD3DB"" />
  </ItemGroup>
</Project>",
                StringCompareShould.IgnoreLineEndings);
        }