Esempio n. 1
0
        private bool LoadMSBuildProject(string projectDirectory, XmlDocument doc)
        {
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);

            namespaceManager.AddNamespace("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003");

            XmlNodeList nodes = doc.SelectNodes("/msbuild:Project/msbuild:PropertyGroup", namespaceManager);

            if (nodes == null)
            {
                return(false);
            }

            XmlElement assemblyNameElement = (XmlElement)doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:AssemblyName", namespaceManager);
            string     assemblyName        = assemblyNameElement.InnerText;

            XmlElement outputTypeElement = (XmlElement)doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:OutputType", namespaceManager);
            string     outputType        = outputTypeElement.InnerText;

            if (outputType == "Exe" || outputType == "WinExe")
            {
                assemblyName = assemblyName + ".exe";
            }
            else
            {
                assemblyName = assemblyName + ".dll";
            }

            foreach (XmlElement configNode in nodes)
            {
                XmlAttribute conditionAttribute = configNode.Attributes["Condition"];
                if (conditionAttribute == null)
                {
                    continue;
                }

                string condition            = conditionAttribute.Value;
                string configurationPrefix  = " '$(Configuration)|$(Platform)' == '";
                string configurationPostfix = "|AnyCPU' ";
                if (!condition.StartsWith(configurationPrefix) || !condition.EndsWith(configurationPostfix))
                {
                    continue;
                }

                string configurationName = condition.Substring(configurationPrefix.Length, condition.Length - configurationPrefix.Length - configurationPostfix.Length);

                XmlElement outputPathElement = (XmlElement)configNode.SelectSingleNode("msbuild:OutputPath", namespaceManager);
                string     outputPath        = outputPathElement.InnerText;

                string outputDirectory = Path.Combine(projectDirectory, outputPath);
                string assemblyPath    = Path.Combine(outputDirectory, assemblyName);

                VSProjectConfig config = new VSProjectConfig(configurationName);
                config.Assemblies.Add(assemblyPath);

                configs.Add(config);
            }

            return(true);
        }
Esempio n. 2
0
        private bool LoadVS2003Project(string projectDirectory, XmlDocument doc)
        {
            XmlNode settingsNode = doc.SelectSingleNode("/VisualStudioProject/*/Build/Settings");

            if (settingsNode == null)
            {
                return(false);
            }

            string assemblyName = RequiredAttributeValue(settingsNode, "AssemblyName");
            string outputType   = RequiredAttributeValue(settingsNode, "OutputType");

            if (outputType == "Exe" || outputType == "WinExe")
            {
                assemblyName = assemblyName + ".exe";
            }
            else
            {
                assemblyName = assemblyName + ".dll";
            }

            XmlNodeList nodes = settingsNode.SelectNodes("Config");

            if (nodes != null)
            {
                foreach (XmlNode configNode in nodes)
                {
                    string name            = RequiredAttributeValue(configNode, "Name");
                    string outputPath      = RequiredAttributeValue(configNode, "OutputPath");
                    string outputDirectory = Path.Combine(projectDirectory, outputPath);
                    string assemblyPath    = Path.Combine(outputDirectory, assemblyName);

                    VSProjectConfig config = new VSProjectConfig(name);
                    config.Assemblies.Add(assemblyPath);

                    configs.Add(config);
                }
            }

            return(true);
        }
		public void Add( VSProjectConfig config )
		{
			List.Add( config );
		}
Esempio n. 4
0
		private bool LoadMSBuildProject(string projectDirectory, XmlDocument doc)
		{
			XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);
			namespaceManager.AddNamespace("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003");

			XmlNodeList nodes = doc.SelectNodes("/msbuild:Project/msbuild:PropertyGroup", namespaceManager);
			if (nodes == null) return false;

			XmlElement assemblyNameElement = (XmlElement)doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:AssemblyName", namespaceManager);
			string assemblyName = assemblyNameElement.InnerText;

			XmlElement outputTypeElement = (XmlElement)doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:OutputType", namespaceManager);
			string outputType = outputTypeElement.InnerText;

			if (outputType == "Exe" || outputType == "WinExe")
				assemblyName = assemblyName + ".exe";
			else
				assemblyName = assemblyName + ".dll";

			foreach (XmlElement configNode in nodes)
			{
                if (configNode.Name != "PropertyGroup")
                    continue;

				XmlAttribute conditionAttribute = configNode.Attributes["Condition"];
				if (conditionAttribute == null) continue;

				string condition = conditionAttribute.Value;
				int start = condition.IndexOf( "==" );
				if ( start < 0 ) continue;

				string configurationName = condition.Substring( start + 2 ).Trim(new char[] {' ', '\'' } );
				if ( configurationName.EndsWith( "|AnyCPU" ) )
					configurationName = configurationName.Substring( 0, configurationName.Length - 7 );

				XmlElement outputPathElement = (XmlElement)configNode.SelectSingleNode("msbuild:OutputPath", namespaceManager);
				string outputPath = outputPathElement.InnerText;

				string outputDirectory = Path.Combine(projectDirectory, outputPath);
				string assemblyPath = Path.Combine(outputDirectory, assemblyName);

				VSProjectConfig config = new VSProjectConfig(configurationName);
				config.Assemblies.Add(assemblyPath);

				configs.Add(config);
			}

			return true;
		}
Esempio n. 5
0
		private bool LoadVS2003Project(string projectDirectory, XmlDocument doc)
		{
			XmlNode settingsNode = doc.SelectSingleNode("/VisualStudioProject/*/Build/Settings");
			if (settingsNode == null)
				return false;

			string assemblyName = RequiredAttributeValue( settingsNode, "AssemblyName" );
			string outputType = RequiredAttributeValue( settingsNode, "OutputType" );

			if (outputType == "Exe" || outputType == "WinExe")
				assemblyName = assemblyName + ".exe";
			else
				assemblyName = assemblyName + ".dll";

			XmlNodeList nodes = settingsNode.SelectNodes("Config");
			if (nodes != null)
				foreach (XmlNode configNode in nodes)
				{
					string name = RequiredAttributeValue( configNode, "Name" );
					string outputPath = RequiredAttributeValue( configNode, "OutputPath" );
					string outputDirectory = Path.Combine(projectDirectory, outputPath);
					string assemblyPath = Path.Combine(outputDirectory, assemblyName);

					VSProjectConfig config = new VSProjectConfig(name);
					config.Assemblies.Add(assemblyPath);

					configs.Add(config);
				}

			return true;
		}
Esempio n. 6
0
		private void Load()
		{
			if ( !IsProjectFile( projectPath ) ) 
				ThrowInvalidFileType( projectPath );

			string projectDirectory = Path.GetFullPath( Path.GetDirectoryName( projectPath ) );
			StreamReader rdr = new StreamReader( projectPath, System.Text.Encoding.UTF8 );
			string[] extensions = {"", ".exe", ".dll", ".lib", "" };
			
			try
			{
				XmlDocument doc = new XmlDocument();
				doc.Load( rdr );

				string extension = Path.GetExtension( projectPath );
				string assemblyName = null;

				switch ( extension )
				{
					case ".vcproj":
						XmlNode topNode = doc.SelectSingleNode( "/VisualStudioProject" );

						// TODO: This is all very hacked up... replace it.
						foreach ( XmlNode configNode in doc.SelectNodes( "/VisualStudioProject/Configurations/Configuration" ) )
						{
							string name = RequiredAttributeValue( configNode, "Name" );
							int config_type = System.Convert.ToInt32(RequiredAttributeValue(configNode, "ConfigurationType" ) );
							string dirName = name;
							int bar = dirName.IndexOf( '|' );
							if ( bar >= 0 )
								dirName = dirName.Substring( 0, bar );
							string outputPath = RequiredAttributeValue( configNode, "OutputDirectory" );
							outputPath = outputPath.Replace( "$(SolutionDir)", Path.GetFullPath( Path.GetDirectoryName( projectPath ) ) + Path.DirectorySeparatorChar );
							outputPath = outputPath.Replace( "$(ConfigurationName)", dirName );

							string outputDirectory = Path.Combine( projectDirectory, outputPath );
							XmlNode toolNode = configNode.SelectSingleNode( "Tool[@Name='VCLinkerTool']" );
							if ( toolNode != null )
							{
								assemblyName = SafeAttributeValue( toolNode, "OutputFile" );
								if ( assemblyName != null )
									assemblyName = Path.GetFileName( assemblyName );
								else
									assemblyName = Path.GetFileNameWithoutExtension(projectPath) + extensions[config_type];
							}
							else
							{
								toolNode = configNode.SelectSingleNode( "Tool[@Name='VCNMakeTool']" );
								if ( toolNode != null )
									assemblyName = Path.GetFileName( RequiredAttributeValue( toolNode, "Output" ) );
							}

							assemblyName = assemblyName.Replace( "$(OutDir)", outputPath );
							assemblyName = assemblyName.Replace( "$(ProjectName)", this.Name );

							VSProjectConfig config = new VSProjectConfig ( name );
							if ( assemblyName != null )
								config.Assemblies.Add( Path.Combine( outputDirectory, assemblyName ) );
							
							this.configs.Add( config );
						}
					
						break;

					case ".csproj":
					case ".vbproj":
					case ".vjsproj":
						LoadProject( projectDirectory, doc );
						break;

					default:
						break;
				}
			}
			catch( FileNotFoundException )
			{
				throw;
			}
			catch( Exception e )
			{
				ThrowInvalidFormat( projectPath, e );
			}
			finally
			{
				rdr.Close();
			}
		}
Esempio n. 7
0
        private bool LoadMSBuildProject(string projectDirectory, XmlDocument doc)
        {
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);

            namespaceManager.AddNamespace("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003");

            XmlNodeList nodes = doc.SelectNodes("/msbuild:Project/msbuild:PropertyGroup", namespaceManager);

            if (nodes == null)
            {
                return(false);
            }

            XmlElement assemblyNameElement = (XmlElement)doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:AssemblyName", namespaceManager);
            string     assemblyName        = assemblyNameElement.InnerText;

            XmlElement outputTypeElement = (XmlElement)doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:OutputType", namespaceManager);
            string     outputType        = outputTypeElement.InnerText;

            if (outputType == "Exe" || outputType == "WinExe")
            {
                assemblyName = assemblyName + ".exe";
            }
            else
            {
                assemblyName = assemblyName + ".dll";
            }

            foreach (XmlElement configNode in nodes)
            {
                if (configNode.Name != "PropertyGroup")
                {
                    continue;
                }

                XmlAttribute conditionAttribute = configNode.Attributes["Condition"];
                if (conditionAttribute == null)
                {
                    continue;
                }

                string condition = conditionAttribute.Value;
                int    start     = condition.IndexOf("==");
                if (start < 0)
                {
                    continue;
                }

                string configurationName = condition.Substring(start + 2).Trim(new char[] { ' ', '\'' });
                if (configurationName.EndsWith("|AnyCPU"))
                {
                    configurationName = configurationName.Substring(0, configurationName.Length - 7);
                }

                XmlElement outputPathElement = (XmlElement)configNode.SelectSingleNode("msbuild:OutputPath", namespaceManager);
                string     outputPath        = outputPathElement.InnerText;

                string outputDirectory = Path.Combine(projectDirectory, outputPath);
                string assemblyPath    = Path.Combine(outputDirectory, assemblyName);

                VSProjectConfig config = new VSProjectConfig(configurationName);
                config.Assemblies.Add(assemblyPath);

                configs.Add(config);
            }

            return(true);
        }
Esempio n. 8
0
        private void Load()
        {
            if (!IsProjectFile(projectPath))
            {
                ThrowInvalidFileType(projectPath);
            }

            string       projectDirectory = Path.GetFullPath(Path.GetDirectoryName(projectPath));
            StreamReader rdr = new StreamReader(projectPath, System.Text.Encoding.UTF8);

            string[] extensions = { "", ".exe", ".dll", ".lib", "" };

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(rdr);

                string extension    = Path.GetExtension(projectPath);
                string assemblyName = null;

                switch (extension)
                {
                case ".vcproj":

                    // TODO: This is all very hacked up... replace it.
                    foreach (XmlNode configNode in doc.SelectNodes("/VisualStudioProject/Configurations/Configuration"))
                    {
                        string name        = RequiredAttributeValue(configNode, "Name");
                        int    config_type = System.Convert.ToInt32(RequiredAttributeValue(configNode, "ConfigurationType"));
                        string dirName     = name;
                        int    bar         = dirName.IndexOf('|');
                        if (bar >= 0)
                        {
                            dirName = dirName.Substring(0, bar);
                        }
                        string outputPath = RequiredAttributeValue(configNode, "OutputDirectory");
                        outputPath = outputPath.Replace("$(SolutionDir)", Path.GetFullPath(Path.GetDirectoryName(projectPath)) + Path.DirectorySeparatorChar);
                        outputPath = outputPath.Replace("$(ConfigurationName)", dirName);

                        string  outputDirectory = Path.Combine(projectDirectory, outputPath);
                        XmlNode toolNode        = configNode.SelectSingleNode("Tool[@Name='VCLinkerTool']");
                        if (toolNode != null)
                        {
                            assemblyName = SafeAttributeValue(toolNode, "OutputFile");
                            if (assemblyName != null)
                            {
                                assemblyName = Path.GetFileName(assemblyName);
                            }
                            else
                            {
                                assemblyName = Path.GetFileNameWithoutExtension(projectPath) + extensions[config_type];
                            }
                        }
                        else
                        {
                            toolNode = configNode.SelectSingleNode("Tool[@Name='VCNMakeTool']");
                            if (toolNode != null)
                            {
                                assemblyName = Path.GetFileName(RequiredAttributeValue(toolNode, "Output"));
                            }
                        }

                        assemblyName = assemblyName.Replace("$(OutDir)", outputPath);
                        assemblyName = assemblyName.Replace("$(ProjectName)", this.Name);

                        VSProjectConfig config = new VSProjectConfig(name);
                        if (assemblyName != null)
                        {
                            config.Assemblies.Add(Path.Combine(outputDirectory, assemblyName));
                        }

                        this.configs.Add(config);
                    }

                    break;

                case ".csproj":
                case ".vbproj":
                case ".vjsproj":
                    LoadProject(projectDirectory, doc);
                    break;

                default:
                    break;
                }
            }
            catch (FileNotFoundException)
            {
                throw;
            }
            catch (Exception e)
            {
                ThrowInvalidFormat(projectPath, e);
            }
            finally
            {
                rdr.Close();
            }
        }
 public void Add(VSProjectConfig config)
 {
     List.Add(config);
 }
Esempio n. 10
0
        public void Load()
        {
            if (!IsProjectFile(projectPath))
            {
                ThrowInvalidFileType(projectPath);
            }

            string projectDirectory = Path.GetFullPath(Path.GetDirectoryName(projectPath));

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(projectPath);

                string extension = Path.GetExtension(projectPath);
                string assemblyName;

                switch (extension)
                {
                case ".vcproj":
                    foreach (XmlNode configNode in doc.SelectNodes("/VisualStudioProject/Configurations/Configuration"))
                    {
                        string  name            = configNode.Attributes["Name"].Value;
                        string  outputPath      = configNode.Attributes["OutputDirectory"].Value;
                        string  outputDirectory = Path.Combine(projectDirectory, outputPath);
                        XmlNode toolNode        = configNode.SelectSingleNode("Tool[@Name='VCLinkerTool']");
                        assemblyName = Path.GetFileName(toolNode.Attributes["OutputFile"].Value);
                        string assemblyPath = Path.Combine(outputDirectory, assemblyName);

                        VSProjectConfig config = new VSProjectConfig(name);
                        config.Assemblies.Add(assemblyPath);

                        this.configs.Add(config);
                    }

                    break;

                case ".csproj":
                case ".vbproj":
                case ".vjsproj":
                    XmlNode settingsNode = doc.SelectSingleNode("/VisualStudioProject/*/Build/Settings");

                    assemblyName = settingsNode.Attributes["AssemblyName"].Value;
                    string outputType = settingsNode.Attributes["OutputType"].Value;

                    if (outputType == "Exe" || outputType == "WinExe")
                    {
                        assemblyName = assemblyName + ".exe";
                    }
                    else
                    {
                        assemblyName = assemblyName + ".dll";
                    }

                    XmlNodeList nodes = settingsNode.SelectNodes("Config");
                    if (nodes != null)
                    {
                        foreach (XmlNode configNode in nodes)
                        {
                            string name            = configNode.Attributes["Name"].Value;
                            string outputPath      = configNode.Attributes["OutputPath"].Value;
                            string outputDirectory = Path.Combine(projectDirectory, outputPath);
                            string assemblyPath    = Path.Combine(outputDirectory, assemblyName);

                            VSProjectConfig config = new VSProjectConfig(name);
                            config.Assemblies.Add(assemblyPath);

                            configs.Add(config);
                        }
                    }

                    break;

                default:
                    break;
                }
            }
            catch (FileNotFoundException)
            {
                throw;
            }
            catch (Exception e)
            {
                ThrowInvalidFormat(projectPath, e);
            }
        }
Esempio n. 11
0
		public void Load()
		{
			if ( !IsProjectFile( projectPath ) )
				ThrowInvalidFileType( projectPath );

			string projectDirectory = Path.GetFullPath( Path.GetDirectoryName( projectPath ) );

			try
			{
				XmlDocument doc = new XmlDocument();
				doc.Load( projectPath );

				string extension = Path.GetExtension( projectPath );
				string assemblyName;

				switch ( extension )
				{
					case ".vcproj":
						foreach ( XmlNode configNode in doc.SelectNodes( "/VisualStudioProject/Configurations/Configuration" ) )
						{
							string name = configNode.Attributes["Name"].Value;
							string outputPath = configNode.Attributes["OutputDirectory"].Value;
							string outputDirectory = Path.Combine( projectDirectory, outputPath );
							XmlNode toolNode = configNode.SelectSingleNode( "Tool[@Name='VCLinkerTool']" );
							assemblyName = Path.GetFileName( toolNode.Attributes["OutputFile"].Value );
							string assemblyPath = Path.Combine( outputDirectory, assemblyName );

							VSProjectConfig config = new VSProjectConfig ( name );
							config.Assemblies.Add( assemblyPath );

							this.configs.Add( config );
						}
					
						break;

					case ".csproj":
					case ".vbproj":
					case ".vjsproj":
						XmlNode settingsNode = doc.SelectSingleNode( "/VisualStudioProject/*/Build/Settings" );
			
						assemblyName = settingsNode.Attributes["AssemblyName"].Value;
						string outputType = settingsNode.Attributes["OutputType"].Value;

						if ( outputType == "Exe" || outputType == "WinExe" )
							assemblyName = assemblyName + ".exe";
						else
							assemblyName = assemblyName + ".dll";

						XmlNodeList nodes = settingsNode.SelectNodes("Config");
						if ( nodes != null ) 
							foreach ( XmlNode configNode in nodes )
							{
								string name = configNode.Attributes["Name"].Value;
								string outputPath = configNode.Attributes["OutputPath"].Value;
								string outputDirectory = Path.Combine( projectDirectory, outputPath );
								string assemblyPath = Path.Combine( outputDirectory, assemblyName );
				
								VSProjectConfig config = new VSProjectConfig ( name );
								config.Assemblies.Add( assemblyPath );

								configs.Add( config );
							}

						break;

					default:
						break;
				}
			}
			catch( FileNotFoundException )
			{
				throw;
			}
			catch( Exception e )
			{
				ThrowInvalidFormat( projectPath, e );
			}
		}