public McCompiler(McFileGenerator genInfo, string mcFile)
        {
            _genInfo = genInfo;
            _mcFile = mcFile;
            _verInfo = new VersionInfoBuilder();

            string[] ns = Path.GetFileNameWithoutExtension(_mcFile).Trim('.').Split('.');
            for (int i = 0; i < ns.Length; i++)
                ns[i] = StronglyTypedResourceBuilder.VerifyResourceName(ns[i], Csharp);
            _namespace = String.Join(".", ns);
        }
예제 #2
0
        public static void ResXtoMc(
            [Argument("output", "out", Description = "The target file path of the mc file to generate.")]
            string outputFile,
            [Argument("input", "in", Description = "The file path of either a resx file, or a project to scan for resx files within.")]
            string[] files
            )
        {
            McFileGenerator gen = new McFileGenerator(files);

            using (Stream io = File.Open(outputFile, FileMode.Create, FileAccess.Write, FileShare.None))
                using (StreamWriter writer = new StreamWriter(io))
                    gen.Write(writer);
        }
예제 #3
0
        public static void ProjectResX(
            [Argument("csproj", Description = "The csproj to generate message file for.")]
            string project,
            [Argument("name", Description = "The relative path and name of the generated resource files.", DefaultValue = "Resources")]
            string naming,
            [Argument("versionInfo", Description = "A csproj containing or an AssemblyInfo.cs file -- or -- a dll to extract version info from.", DefaultValue = null)]
            string versionInfo,
            [Argument("resources", Description = "A string to inject into the resource script file prior to compilation.", DefaultValue = null)]
            string resourceScript,
            [Argument("tools", Description = "The directory used to locate the mc.exe and rc.exe command line tools.", DefaultValue = null)]
            string toolsBin
            )
        {
            FauxProject proj = new FauxProject(project);
            Dictionary <string, string> vars = proj.GetProjectVariables();

            string mcFile  = Path.Combine(Path.GetDirectoryName(project), naming + ".mc");
            string dir     = Path.GetDirectoryName(mcFile);
            string projDir = Path.GetDirectoryName(project);

            Directory.CreateDirectory(dir);

            string nsSuffix = Path.GetDirectoryName(naming).Replace('/', '.').Replace('\\', '.').Trim('.');

            if (!String.IsNullOrEmpty(nsSuffix))
            {
                nsSuffix = "." + nsSuffix;
            }

            McFileGenerator gen = new McFileGenerator(new string[] { project });

            using (Stream io = File.Open(mcFile, FileMode.Create, FileAccess.Write, FileShare.None))
                using (StreamWriter writer = new StreamWriter(io))
                    gen.Write(writer);

            McCompiler mc = new McCompiler(gen, mcFile);

            mc.IntermediateFiles = dir;
            mc.Namespace         = String.Format("{0}{1}", vars["RootNamespace"], nsSuffix);

            if (!String.IsNullOrEmpty(versionInfo))
            {
                mc.VersionInfo.ReadFrom(versionInfo);
            }
            else
            {
                mc.VersionInfo.ReadFrom(project);
            }

            if (!String.IsNullOrEmpty(toolsBin))
            {
                mc.ToolsBin = toolsBin;
            }

            if (vars.ContainsKey("ApplicationIcon"))
            {
                mc.IconFile = Path.Combine(projDir, vars["ApplicationIcon"]);
            }

            if (vars.ContainsKey("ApplicationManifest"))
            {
                mc.ManifestFile = Path.Combine(projDir, vars["ApplicationManifest"]);
            }

            string rcFile;

            mc.ResourceScript = resourceScript;
            mc.CreateResFile(vars["TargetFileName"], out rcFile);
            File.WriteAllText(Path.ChangeExtension(rcFile, ".Constants.cs"), mc.CreateConstants(Path.ChangeExtension(rcFile, ".h")));
            File.WriteAllText(Path.ChangeExtension(rcFile, ".InstallUtil.cs"), mc.CreateInstaller());
        }
예제 #4
0
        public static void ResXtoMessageDll(
            [Argument("output", "out", Description = "The target assembly name to generate.")]
            string outputFile,
            [Argument("input", "in", Description = "The file path of either a resx file, or a project to scan for resx files within.")]
            string[] files,
            [Argument("intermediate", "temp", Description = "A directory used for intermediate files.", DefaultValue = "%TEMP%")]
            string intermediateFiles,
            [Argument("versionInfo", Description = "A csproj containing or an AssemblyInfo.cs file -- or -- a dll to extract version info from.", DefaultValue = null)]
            string versionInfo,
            [Argument("namespace", Description = "The namespace to use for the embedded constants and install utility classes.", DefaultValue = null)]
            string nameSpace,
            [Argument("tools", Description = "The directory used to locate the mc.exe and rc.exe command line tools.", DefaultValue = null)]
            string toolsBin,
            [Argument("csc", Description = "Additional options to provide to the csc command line compiler.", DefaultValue = "")]
            string cscOptions
            )
        {
            string tempDir = null;

            try
            {
                if (intermediateFiles == "%TEMP%")
                {
                    intermediateFiles = tempDir = Path.GetTempFileName();
                    File.Delete(intermediateFiles);
                }
                else
                {
                    intermediateFiles = Path.GetFullPath(Environment.ExpandEnvironmentVariables(intermediateFiles));
                }

                string mcFile = Path.Combine(intermediateFiles, Path.GetFileNameWithoutExtension(outputFile) + ".mc");

                McFileGenerator gen = new McFileGenerator(files);
                using (Stream io = File.Open(mcFile, FileMode.Create, FileAccess.Write, FileShare.None))
                    using (StreamWriter writer = new StreamWriter(io))
                        gen.Write(writer);

                McCompiler mc = new McCompiler(gen, mcFile);
                mc.IntermediateFiles = intermediateFiles;

                if (!String.IsNullOrEmpty(nameSpace))
                {
                    mc.Namespace = nameSpace;
                }

                if (!String.IsNullOrEmpty(versionInfo))
                {
                    mc.VersionInfo.ReadFrom(versionInfo);
                }

                if (!String.IsNullOrEmpty(toolsBin))
                {
                    mc.ToolsBin = toolsBin;
                }

                mc.Compile(outputFile, cscOptions ?? "");
            }
            catch
            {
                tempDir = null;
            }
            finally
            {
                if (tempDir != null)
                {
                    try
                    {
                        Directory.Delete(tempDir, true);
                    }
                    catch
                    {
                    }
                }
            }
        }