Example #1
0
        public void PublishLayer_ComplexSolution_LayersGenerated()
        {
            var projects = new SolutionConfiguration
            {
                NugetConfig = new NugetConfiguration().Add("artifacts", "artifacts"),
                Projects    =
                {
                    new Project
                    {
                        Name = "app1",
                        // SlnRelativeDir = ".",
                        Sdk           = Sdks.Microsoft_NET_Sdk,
                        PropertyGroup ={ OutputType                     = "exe", TargetFramework = "netcoreapp3.1" },
                    },
                    new Project()
                    {
                        Name = "classlib",
                        // SlnRelativeDir = ".",
                        Sdk           = Sdks.Microsoft_NET_Sdk,
                        PropertyGroup ={ TargetFramework                = "netcoreapp3.1" },
                    }
                }
            }.Generate(_testDir);
            var projectFile = projects
                              .Where(x => x.Value.Name == "app1")
                              .Select(x => x.Key)
                              .First();

            DotNet($@"add {projectFile} reference ..{Path.DirectorySeparatorChar}classlib{Path.DirectorySeparatorChar}classlib.csproj", projectFile.Parent);
            DotNet($@"add {projectFile} package NMica -v {TestsSetup.NMicaVersion.NuGetPackageVersion} ");
            DotNet($@"add {projectFile} package Serilog -v 2.9.1-dev-01154 ");
            DotNet($@"add {projectFile} package Newtonsoft.Json -v 12.0.1 ");
            DotNetRestore(_ => _
                          .SetProjectFile(projectFile));

            var cliPublishDir = _testDir / "cli-layers";

            DotNet($"msbuild /t:PublishLayer /p:PublishDir={cliPublishDir} /p:DockerLayer=All {projectFile} /p:GenerateDockerfile=False");
            AssertLayers(cliPublishDir);

            var msbuildPublishDir = _testDir / "msbuild-layers";

            MSBuildTasks.MSBuild(_ => _
                                 .SetProjectFile(projectFile)
                                 .SetTargets("PublishLayer")
                                 .AddProperty("PublishDir", msbuildPublishDir)
                                 .AddProperty("DockerLayer", "All")
                                 .AddProperty("GenerateDockerfile", false));
            AssertLayers(msbuildPublishDir);

            void AssertLayers(AbsolutePath publishDir)
            {
                FileExists(publishDir / "package" / "Newtonsoft.Json.dll").Should().BeTrue();
                FileExists(publishDir / "earlypackage" / "Serilog.dll").Should().BeTrue();
                FileExists(publishDir / "project" / "classlib.dll").Should().BeTrue();
                FileExists(publishDir / "app" / "app1.dll").Should().BeTrue();
            }
        }
Example #2
0
 protected override void OnExecute()
 {
     MSBuildTasks.MSBuild(s => s
                          .SetProjectFile(BuildInfo.Solution)
                          .SetConfiguration(BuildInfo.Configuration)
                          .SetAssemblyVersion(BuildInfo.VersionInfo.GetAssemblySemVer())
                          .SetFileVersion(BuildInfo.VersionInfo.GetAssemblySemFileVer())
                          .SetInformationalVersion(BuildInfo.VersionInfo.InformationalVersion)
                          .DisableRestore());
 }
Example #3
0
 /// <summary>
 /// msbuild
 /// </summary>
 public static ITargetDefinition Build(ITargetDefinition _, IMsBuild build) => _
 .DependsOn(build.Restore)
 .Executes(
     () =>
 {
     MSBuildTasks
     .MSBuild(
         settings =>
         settings
         .SetSolutionFile(build.Solution)
         .SetConfiguration(build.Configuration)
         .SetDefaultLoggers(build.LogsDirectory / "build.log")
         .SetGitVersionEnvironment(build.GitVersion)
         .SetAssemblyVersion(build.GitVersion.AssemblySemVer)
         .SetPackageVersion(build.GitVersion.NuGetVersionV2)
         );
 }
     );