Click here to Skip to main content
15,881,882 members
Articles / Web Development / ASP.NET

Straight way to create ASP.NET user controls library

Rate me:
Please Sign up or sign in to vote.
4.71/5 (5 votes)
20 Mar 2009Ms-PL7 min read 121.9K   3.5K   45  
My post-build tool transforming any WebApplication into a library containing .ascx controls.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace WebLibraryMaker
{
    public static class AspnetCompiler
    {
        public static int PrecompileWebApplication(Pathes pathes, bool debug)
        {
            string debugOption = "";
            if (debug) debugOption = "-d ";

            Process process = new Process();
            process.StartInfo.FileName = Path.Combine(pathes.DotNetDirectory, "aspnet_compiler.exe");
            process.StartInfo.Arguments = String.Concat(debugOption, "-f \"", pathes.TemporaryDirectory, "\" -v \"", pathes.ProjectName, "\" -p \"", pathes.ProjectDirectory, "\"");
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            Console.Write(process.StandardOutput.ReadToEnd());
            Console.Error.Write(process.StandardError.ReadToEnd());
            process.WaitForExit();
            if (process.ExitCode != 0) return process.ExitCode;

            Directory.SetCurrentDirectory(pathes.CompiledDirectory);

            return 0;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Senior) HRsoft
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions