Beispiel #1
0
        public static MSBuildProj GetProject(string filePath, string targetFramework, bool forceNew, bool build, ILogger logger, bool globalTool = false)
        {
            MSBuildProj project = null;

            var projectDir     = Path.GetDirectoryName(filePath);
            var srcProgramFile = Path.Combine(projectDir, "Program.cs");
            var dstProgramFile = Path.Combine(projectDir, $"{Path.GetFileNameWithoutExtension(filePath)}.cs");

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            if (forceNew && File.Exists(filePath))
            {
                File.Delete(filePath);
                if (File.Exists(dstProgramFile))
                {
                    File.Delete(dstProgramFile);
                }
                FileUtil.TryDeleteDirectory(Path.Combine(Path.GetDirectoryName(filePath), "obj"));
            }

            if (File.Exists(filePath))
            {
                project = MSBuildProj.FromPathAsync(filePath, logger, token).Result;
            }
            else
            {
                project = MSBuildProj.DotNetNewAsync(filePath, logger, token).Result;
                File.Move(srcProgramFile, dstProgramFile);
            }

            Assert.NotNull(project);

            if (!string.IsNullOrEmpty(targetFramework))
            {
                project.TargetFramework = targetFramework;
            }

            if (!globalTool)
            {
                var svcutilPkgVersion = E2ETest.GetSvcutilPkgVersionAndFeed();
                var svcutilPkgRef     = ProjectDependency.FromPackage("dotnet-svcutil-lib", svcutilPkgVersion);
                if (!project.Dependencies.Any(d => d.Equals(svcutilPkgRef)))
                {
                    bool success = project.AddDependency(svcutilPkgRef);
                    Assert.True(success, $"Could not add tool package dependency: dotnet-svcutil-lib.{svcutilPkgVersion}");
                }
            }

            var ret = project.RestoreAsync(logger, token).Result;

            Assert.True(ret.ExitCode == 0, $"Project package restore failed:{Environment.NewLine}{ret.OutputText}{logger}");

            if (build)
            {
                ret = project.BuildAsync(logger, token).Result;
                Assert.True(ret.ExitCode == 0, $"Project build failed:{Environment.NewLine}{ret.OutputText}{logger}");
            }

            return(project);
        }
Beispiel #2
0
        private string SetupProjectDependencies()
        {
            var libProjPath  = Path.Combine(this_TestGroupOutputDir, "TypesLib", "TypesLib.csproj");
            var binProjPath  = Path.Combine(this_TestGroupOutputDir, "BinLib", "BinLib.csproj");
            var assemblyPath = Path.Combine(Path.GetDirectoryName(binProjPath), "bin", "Debug", "netstandard1.3", "BinLib.dll");

            if (!File.Exists(assemblyPath))
            {
                var typeReuseProjectsPath = Path.Combine(g_TestCasesDir, "TypeReuse");

                FileUtil.CopyDirectory(typeReuseProjectsPath, this_TestGroupOutputDir);
                CreateGlobalJson(this_TestGroupOutputDir, this_TestCaseProject.SdkVersion);

                MSBuildProj binProj = MSBuildProj.FromPathAsync(binProjPath, null, CancellationToken.None).Result;
                ProcessRunner.ProcessResult result = binProj.BuildAsync(true, null, CancellationToken.None).Result;
                Assert.True(result.ExitCode == 0, result.OutputText);
            }

            Assert.True(File.Exists(binProjPath), $"{nameof(binProjPath)} not initialized!");
            Assert.True(File.Exists(libProjPath), $"{nameof(libProjPath)} not initialized!");

            this_TestCaseProject.AddDependency(ProjectDependency.FromAssembly(assemblyPath));
            this_TestCaseProject.AddDependency(ProjectDependency.FromProject(libProjPath));
            this_TestCaseProject.SaveAsync(this_TestCaseLogger, CancellationToken.None).Wait();

            ProcessRunner.ProcessResult ret = this_TestCaseProject.BuildAsync(true, this_TestCaseLogger, CancellationToken.None).Result;
            Assert.True(ret.ExitCode == 0, ret.OutputText);

            // keep the boostrapper projects in the outputs to be evaluated against baselines.
            this_TestCaseBootstrapDir = this_TestCaseOutputDir;
            Directory.CreateDirectory(Path.Combine(this_TestCaseBootstrapDir, "SvcutilBootstrapper"));

            var uri = PathHelper.GetRelativePath(Path.Combine(this_TestGroupOutputDir, "TypeReuseSvc.wsdl"), new DirectoryInfo(this_TestCaseOutputDir));

            return(uri);
        }