简体   繁体   中英

Extracting all source code from visual studio express 2010 project into a single file?

How to extract all source code from a single c# project to a single file? Preferably not by copy-paste?

a very simple approach with the command line

for %f in (*.cs) do type %f >> result.txt

EDIT:

With recursion & file info

for /R %f in (*.cs) do echo ----- %f ----- >> result.txt & type %f >> result.txt

Simply pass in the path to the solution directory from the command line.

class Program
{
    static StringBuilder builder = new StringBuilder();

    static void Main(string[] args)
    {
        if (args.Length == 0)
            return;

        string directory = args[0];

        ProcessDirectories(directory);

        // Save file here
    }

    static void ProcessDirectories(string root)
    {
        ProcessDirectory(new DirectoryInfo(root));

        var subDirectories = Directory.GetDirectories(root);

        if (subDirectories.Length == 0)
            return;

        foreach (var subDirectory in subDirectories)
        {
            ProcessDirectories(subDirectory);
        }
    }

    static void ProcessDirectory(DirectoryInfo directory)
    {
        foreach (var file in directory.EnumerateFiles())
        {
            builder.AppendFormat("----- {0} -----", file.FullName);

            using (var reader = file.OpenText())
            {
                builder.AppendLine(reader.ReadToEnd());
            }
        }
    }
}

Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM