Example #1
0
        public string SetupProject()
        {
            string projectRoot = "webapi";
            string csproj      = Path.Combine(projectRoot, $"{projectRoot}.csproj");

            if (File.Exists(csproj))
            {
                LogMessage($"using existing project {csproj}");
                return(csproj);
            }

            if (Directory.Exists(projectRoot))
            {
                Directory.Delete(projectRoot, true);
            }

            Directory.CreateDirectory(projectRoot);
            int ret = CommandHelper.Dotnet("new webapi", projectRoot);

            if (ret != 0)
            {
                LogMessage("dotnet new failed");
                Assert.True(false);
            }

            PreventPublishFiltering(csproj);

            AddLinkerReference(csproj);

            return(csproj);
        }
Example #2
0
        public string SetupProject()
        {
            string projectRoot = CreateTestFolder("helloworld");
            string csproj      = Path.Combine(projectRoot, $"helloworld.csproj");

            if (File.Exists(csproj))
            {
                LogMessage($"using existing project {csproj}");
                return(csproj);
            }

            if (Directory.Exists(projectRoot))
            {
                Directory.Delete(projectRoot, true);
            }

            Directory.CreateDirectory(projectRoot);
            int ret = CommandHelper.Dotnet("new console", projectRoot);

            if (ret != 0)
            {
                LogMessage("dotnet new failed");
                Assert.True(false);
            }

            AddLinkerReference(csproj);

            AddNuGetConfig(projectRoot);

            return(csproj);
        }
        /// <summary>
        ///   Run the linker on the specified project. This assumes
        ///   that the project already contains a reference to the
        ///   linker task package.
        ///   Optionally takes a list of root descriptor files.
        ///   Returns the path to the built app, either the renamed
        ///   host for self-contained publish, or the dll containing
        ///   the entry point.
        /// </summary>
        public string BuildAndLink(string csproj, List <string> rootFiles = null, Dictionary <string, string> extraPublishArgs = null, bool selfContained = false)
        {
            string demoRoot = Path.GetDirectoryName(csproj);

            string publishArgs = $"publish -c {TestContext.Configuration} /v:n /p:ShowLinkerSizeComparison=true";

            if (selfContained)
            {
                publishArgs += $" -r {TestContext.RuntimeIdentifier}";
            }
            string rootFilesStr;

            if (rootFiles != null && rootFiles.Any())
            {
                rootFilesStr = String.Join(";", rootFiles);
                publishArgs += $" /p:LinkerRootDescriptors={rootFilesStr}";
            }
            if (extraPublishArgs != null)
            {
                foreach (var item in extraPublishArgs)
                {
                    publishArgs += $" /p:{item.Key}={item.Value}";
                }
            }
            int ret = CommandHelper.Dotnet(publishArgs, demoRoot);

            if (ret != 0)
            {
                LogMessage("publish failed, returning " + ret);
                Assert.True(false);
            }

            // detect the target framework for which the app was published
            string tfmDir   = Path.Combine(demoRoot, "bin", TestContext.Configuration);
            string tfm      = Directory.GetDirectories(tfmDir).Select(p => Path.GetFileName(p)).Single();
            string builtApp = Path.Combine(tfmDir, tfm);

            if (selfContained)
            {
                builtApp = Path.Combine(builtApp, TestContext.RuntimeIdentifier);
            }
            builtApp = Path.Combine(builtApp, "publish",
                                    Path.GetFileNameWithoutExtension(csproj));
            if (selfContained)
            {
                if (TestContext.RuntimeIdentifier.Contains("win"))
                {
                    builtApp += ".exe";
                }
            }
            else
            {
                builtApp += ".dll";
            }
            Assert.True(File.Exists(builtApp));
            return(builtApp);
        }