Beispiel #1
0
        public async System.Threading.Tasks.Task ExecuteCore()
        {
            if (string.IsNullOrEmpty(OutputDirectory))
            {
                throw new ArgumentException("OutputDirectory is not set.");
            }

            DummyProject project = new DummyProject();

            foreach (var source in Sources)
            {
                string sourceFile = source.ItemSpec;
                if (!File.Exists(sourceFile))
                {
                    throw new FileNotFoundException(sourceFile);
                }

                string generatedFile = Path.Combine(OutputDirectory, sourceFile);

                string targetDirectory = Path.GetDirectoryName(generatedFile);
                Directory.CreateDirectory(targetDirectory);

                await project.GenerateDummy(source.ItemSpec, generatedFile);

                _generatedFiles.Add(new TaskItem(generatedFile));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add menu that browse for assembly to reference.
        /// </summary>
        private void AddProjectBrowsing()
        {
            Project     p           = new DummyProject(SharedStrings.ReferenceProject_Browse);
            MenuCommand menuCommand = AddProject(ID - 1, p.Name, 1, 9012, Property_ReferenceProject, p, false);

            vsCommands.Add(p, menuCommand);
        }
Beispiel #3
0
        public async Task Run(Options options)
        {
            if (Directory.Exists(options.InputPath))
            {
                options.IsMultiple = true;
            }

            if (options.IsMultiple)
            {
                if (string.IsNullOrEmpty(options.OutputPath) || !Directory.Exists(options.OutputPath))
                {
                    ExitWithError("Directory should be set as the output path.");
                }
                DirectoryInfo inputDirInfo = new DirectoryInfo(options.InputPath);
                inputFiles = inputDirInfo.GetFiles("*.cs", SearchOption.AllDirectories);
            }
            else
            {
                if (!File.Exists(options.InputPath))
                {
                    ExitWithError("Couldn't find the input file : " + options.InputPath);
                }
                FileInfo fileInfo = new FileInfo(options.InputPath);
                inputFiles = new FileInfo[] { fileInfo };
            }

            DummyProject project = new DummyProject();

            Regex rgx = new Regex("^" + options.InputPath.Replace("\\", "\\\\"));

            foreach (var f in inputFiles)
            {
                if (string.IsNullOrEmpty(options.OutputPath))
                {
                    await project.GenerateDummy(f.FullName);
                }
                else if (Directory.Exists(options.OutputPath))
                {
                    var outputFile = rgx.Replace(f.FullName, options.OutputPath);
                    Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
                    await project.GenerateDummy(f.FullName, outputFile);
                }
                else
                {
                    await project.GenerateDummy(f.FullName, options.OutputPath);
                }

                if (options.Verbose)
                {
                    Console.WriteLine($"Processed : {f.FullName}");
                }
            }
        }
        public async Task EnsureProjectFactoryWorksAsExpectedWithReferenceOutputAssemblyValuesComplex()
        {
            // Setup
            var nugetexe = Util.GetNuGetExePath();

            using (var workingDirectory = TestDirectory.Create())
            {
                // Setup the projects
                var link = new DummyProject("Link", Path.Combine(workingDirectory, "Link", "Link.csproj"));
                var a    = new DummyProject("A", Path.Combine(workingDirectory, "A", "A.csproj"));
                var b    = new DummyProject("B", Path.Combine(workingDirectory, "B", "B.csproj"));
                var c    = new DummyProject("C", Path.Combine(workingDirectory, "C", "C.csproj"));
                var d    = new DummyProject("D", Path.Combine(workingDirectory, "D", "D.csproj"));
                var e    = new DummyProject("E", Path.Combine(workingDirectory, "E", "E.csproj"));
                link.AddProjectReference(a, false);
                link.AddProjectReference(b, true);
                a.AddProjectReference(c, false);
                c.AddProjectReference(d, true);
                b.AddProjectReference(e, false);
                link.WriteToFile();
                a.WriteToFile();
                b.WriteToFile();
                c.WriteToFile();
                d.WriteToFile();
                e.WriteToFile();

                // Act
                var r = CommandRunner.Run(
                    nugetexe,
                    workingDirectory,
                    $"pack Link{Path.DirectorySeparatorChar}Link.csproj -build -IncludeReferencedProjects -Version 1.0.0",
                    waitForExit: true);

                // Assert
                Util.VerifyResultSuccess(r);

                using (var package = new PackageArchiveReader(Path.Combine(workingDirectory, "Link.1.0.0.nupkg")))
                {
                    var files = (await package.GetPackageFilesAsync(PackageSaveMode.Files, CancellationToken.None)).ToArray();

                    Assert.Equal(0, r.Item1);
                    Array.Sort(files);
                    Assert.Equal(
                        files,
                        new[]
                    {
                        @"lib/net45/A.dll",
                        @"lib/net45/C.dll",
                        @"lib/net45/Link.dll"
                    });
                }
            }
        }
        public async Task ParseCsproj_Success(string csprojFileName)
        {
            var projectLocation = await DummyProject.Generate("TestProject");

            var crawler       = new ProjectCrawler();
            var dotnetProject = await crawler.ParseCsproj(Path.Combine(projectLocation, csprojFileName));

            await DummyProject.Clean("TestProject");

            Assert.Equal("TestProject", dotnetProject.Name);
            Assert.Equal("Microsoft.NET.Sdk.Web", dotnetProject.ProjectSdk);
        }
            private static XElement GenerateProjectReference(DummyProject project, bool exclude)
            {
                var projectReferenceXElement = new XElement(MSBuildNS + "ProjectReference",
                                                            new XAttribute("Include", project.Location),
                                                            new XElement(MSBuildNS + "Project", project.Id),
                                                            new XElement(MSBuildNS + "Name", project.Name));

                if (exclude)
                {
                    projectReferenceXElement.Add(new XElement(MSBuildNS + "ReferenceOutputAssembly", "false"));
                }

                return(projectReferenceXElement);
            }
Beispiel #7
0
        public void EnsureProjectFactoryWorksAsExpectedWithReferenceOutputAssemblyValuesComplex()
        {
            // Setup
            var nugetexe = Util.GetNuGetExePath();

            using (var workingDirectory = TestFileSystemUtility.CreateRandomTestFolder())
            {
                // Setup the projects
                DummyProject link = new DummyProject("Link", Path.Combine(workingDirectory, "Link\\Link.csproj"));
                DummyProject a    = new DummyProject("A", Path.Combine(workingDirectory, "A\\A.csproj"));
                DummyProject b    = new DummyProject("B", Path.Combine(workingDirectory, "B\\B.csproj"));
                DummyProject c    = new DummyProject("C", Path.Combine(workingDirectory, "C\\C.csproj"));
                DummyProject d    = new DummyProject("D", Path.Combine(workingDirectory, "D\\D.csproj"));
                DummyProject e    = new DummyProject("E", Path.Combine(workingDirectory, "E\\E.csproj"));
                link.AddProjectReference(a, false);
                link.AddProjectReference(b, true);
                a.AddProjectReference(c, false);
                c.AddProjectReference(d, true);
                b.AddProjectReference(e, false);
                link.WriteToFile();
                a.WriteToFile();
                b.WriteToFile();
                c.WriteToFile();
                d.WriteToFile();
                e.WriteToFile();

                // Act
                var r = CommandRunner.Run(
                    nugetexe,
                    workingDirectory,
                    "pack Link\\Link.csproj -build -IncludeReferencedProjects -Version 1.0.0",
                    waitForExit: true);

                // Assert
                Util.VerifyResultSuccess(r);
                var package = new OptimizedZipPackage(Path.Combine(workingDirectory, "Link.1.0.0.nupkg"));
                var files   = package.GetFiles().Select(f => f.Path).ToArray();

                Assert.Equal(0, r.Item1);
                Array.Sort(files);
                Assert.Equal(files, new[] {
                    @"lib\net45\A.dll",
                    @"lib\net45\C.dll",
                    @"lib\net45\Link.dll"
                });
            }
        }
        public void EnsureProjectFactoryWorksAsExpectedWithReferenceOutputAssemblyValuesBasic()
        {
            // Setup
            var nugetexe = Util.GetNuGetExePath();

            using (var workingDirectory = TestDirectory.Create())
            {
                // Setup the projects
                DummyProject link = new DummyProject("Link", Path.Combine(workingDirectory, "Link", "Link.csproj"));
                DummyProject a    = new DummyProject("A", Path.Combine(workingDirectory, "A", "A.csproj"));
                DummyProject b    = new DummyProject("B", Path.Combine(workingDirectory, "B", "B.csproj"));
                link.AddProjectReference(a, false);
                link.AddProjectReference(b, true);
                link.WriteToFile();
                a.WriteToFile();
                b.WriteToFile();

                // Act
                var r = CommandRunner.Run(
                    nugetexe,
                    workingDirectory,
                    $"pack Link{Path.DirectorySeparatorChar}Link.csproj -build -IncludeReferencedProjects -Version 1.0.0",
                    waitForExit: true);

                // Assert
                Util.VerifyResultSuccess(r);

                var package = new PackageArchiveReader(Path.Combine(workingDirectory, "Link.1.0.0.nupkg"));
                var files   = package.GetPackageFiles(PackageSaveMode.Files).ToArray();

                Assert.Equal(0, r.Item1);
                Array.Sort(files);
                Assert.Equal(files, new[] {
                    @"lib/net45/A.dll",
                    @"lib/net45/Link.dll"
                });
            }
        }
            public void AddProjectReference(DummyProject project, bool exclude)
            {
                var projectReferenceElement = GenerateProjectReference(project, exclude);

                ProjectReferences.Add(projectReferenceElement);
            }