private static string GetConfigPath(FrameworkVersions toolsVersion)
        {
            string config = String.Format("CSharpTest.Net.CSBuild.{0}.config", toolsVersion.ToString());
            using (TextReader rdr = new StreamReader(typeof(BuildEngine).Assembly.GetManifestResourceStream(config)))
                config = rdr.ReadToEnd();

            string tmpConfig = Path.Combine(Path.GetTempPath(), String.Format("CSBuildEngine.{0}.config", toolsVersion.ToString()));
            File.WriteAllText(tmpConfig, config);
            return tmpConfig;
        }
Beispiel #2
0
        private static Engine CreateEngine(FrameworkVersions toolsVersion, string frameworkPath)
        {
            Engine engine = new Engine(frameworkPath);

            Version fullVersion = engine.GetType().Assembly.GetName().Version;
            string  version     = fullVersion.ToString(2);

            if (toolsVersion == FrameworkVersions.v30 && version == "2.0")
            {
                version = "3.0";                //these use the same build runtime: 2.0/3.0
            }
            if (toolsVersion == FrameworkVersions.v45 && version == "4.0")
            {
                version = "4.5";//these use the same build runtime: 4.0/4.5
            }
            if (version.Replace(".", "") != toolsVersion.ToString().TrimStart('v'))
            {
                throw new ApplicationException(String.Format("Expected runtime {0}, found ({1}){2}.", toolsVersion, version, fullVersion));
            }

            Log.Verbose("Using build engine: {0}", engine.GetType().Assembly.FullName);

            if (toolsVersion == FrameworkVersions.v20 || toolsVersion == FrameworkVersions.v30)
            {
                engine.GlobalProperties.SetProperty("MSBuildToolsPath", frameworkPath);
            }

            //<property name="FrameworkSDKDir" value="%ProgramFiles%\Microsoft.NET\SDK\v2.0\" global="true"/>
            //if (!Directory.Exists(engine.GlobalProperties.SetProperty()))
            //{ }


            new MSBuildLog(engine);
            return(engine);
        }
		private static Engine CreateEngine(FrameworkVersions toolsVersion, string frameworkPath)
        {
			Engine engine = new Engine(frameworkPath);

			Version fullVersion = engine.GetType().Assembly.GetName().Version;
			string version = fullVersion.ToString(2);
			if (toolsVersion == FrameworkVersions.v30 && version == "2.0")
				version = "3.0";//these use the same build runtime: 2.0/3.0
		    if (toolsVersion == FrameworkVersions.v45 && version == "4.0")
                version = "4.5";//these use the same build runtime: 4.0/4.5

			if (version.Replace(".", "") != toolsVersion.ToString().TrimStart('v'))
                throw new ApplicationException(String.Format("Expected runtime {0}, found ({1}){2}.", toolsVersion, version, fullVersion));

            Log.Verbose("Using build engine: {0}", engine.GetType().Assembly.FullName);

			if (toolsVersion == FrameworkVersions.v20 || toolsVersion == FrameworkVersions.v30)
				engine.GlobalProperties.SetProperty("MSBuildToolsPath", frameworkPath);

			//<property name="FrameworkSDKDir" value="%ProgramFiles%\Microsoft.NET\SDK\v2.0\" global="true"/>
			//if (!Directory.Exists(engine.GlobalProperties.SetProperty()))
			//{ }


            new MSBuildLog(engine);
            return engine;
        }
        private static string GetConfigPath(FrameworkVersions toolsVersion)
        {
            string config = String.Format("CSharpTest.Net.CSBuild.{0}.config", toolsVersion.ToString());

            using (TextReader rdr = new StreamReader(typeof(BuildEngine).Assembly.GetManifestResourceStream(config)))
                config = rdr.ReadToEnd();

            string tmpConfig = Path.Combine(Path.GetTempPath(), String.Format("CSBuildEngine.{0}.config", toolsVersion.ToString()));

            File.WriteAllText(tmpConfig, config);
            return(tmpConfig);
        }
        /// <summary>
        /// Check if a specific .NET Framework version is installed.
        /// </summary>
        /// <param name="version">version to test</param>
        /// <returns>True if installed</returns>
        public static bool IsVersionInstalled(FrameworkVersions version)
        {
            try
            {
                switch (version)
                {
                case FrameworkVersions.Mono_2_4:

                    if (!string.IsNullOrEmpty(MonoVersion))
                    {
                        Regex regex = new Regex(@"^Mono (?<major>\d+)\.(?<minor>\d+)(\..*)?$");
                        if (regex.IsMatch(MonoVersion))
                        {
                            string[] items = regex.Split(MonoVersion);

                            int major = Convert.ToInt32(items[regex.GroupNumberFromName("major")]);
                            int minor = Convert.ToInt32(items[regex.GroupNumberFromName("minor")]);

                            return((major == 2 && minor >= 4) || (major >= 3));
                        }
                    }
                    break;

                default:
                    RegistryKey masterKey = Registry.LocalMachine.OpenSubKey(REG_LOCATION);

                    if (masterKey != null)
                    {
                        string[] SubKeyNames = masterKey.GetSubKeyNames();
                        foreach (string ver in SubKeyNames)
                        {
                            if (ver.ToLower().Replace(".", "_") == version.ToString())
                            {
                                return(true);
                            }
                        }
                    }
                    break;
                }
            }
            catch (Exception)
            {
            }

            return(false);
        }
        /// <summary>
        /// Check if a specific .NET Framework version is installed.
        /// </summary>
        /// <param name="version">version to test</param>
        /// <returns>True if installed</returns>
        public static bool IsVersionInstalled(FrameworkVersions version)
        {
            try
            {
                switch (version)
                {
                    case FrameworkVersions.Mono_2_4:

                        if (!string.IsNullOrEmpty(MonoVersion))
                        {
                            var regex = new Regex(@"^Mono (?<major>\d+)\.(?<minor>\d+)(\..*)?$");
                            if (regex.IsMatch(MonoVersion))
                            {
                                var items = regex.Split(MonoVersion);

                                var major = Convert.ToInt32(items[regex.GroupNumberFromName("major")]);
                                var minor = Convert.ToInt32(items[regex.GroupNumberFromName("minor")]);

                                return (major == 2 && minor >= 4) || (major >= 3);
                            }
                        }
                        break;
                    default:
                        var masterKey = Registry.LocalMachine.OpenSubKey(RegLocation);

                        if (masterKey != null)
                        {
	                        var subKeyNames = masterKey.GetSubKeyNames();
	                        if (subKeyNames.Any(ver => ver.ToLower().Replace(".", "_") == version.ToString()))
		                        return true;
                        }
		                break;
                }
            }
            catch (Exception)
            {
				return false;
			}

            return false;
        }