Configuring an Oxygene Project in VS programmatically

Hi,

I know how to open and drive VS 2012 from my applications code by automation
then create a project of type oxygene class,
then add an downloaded OpenVMS pascal file to the project,
then run a pre-build Txl process converting the file from OpenVMS Pascal to Oxygene Pascal
. . . still a few things missing . . .

the major issues I have is maybe simple:
how do I have to change the oxygene’s project properties compatibility checkboxes programmatically? i.e. I want to check-on "Allow globals, allow legacy with, allow implicit var/out in method calls, allow Delphi compatibility syntax, Use Delphi compatibility division operators; all others to check-off;

any clues/hints before I dive at the wrong place to deep is welcome!

I don’t believe we have APIs for this. You probably could adjust the project’s XML?

I was hoping that the Oxygene Integration in to Visual Studion is using some EnvDTE API approach. I was hoping that one could say a few words which item/properties in this larger world/context is maybe known by a name, a name leading to a properties page which keeps the compatibility properties. Any I know, all is somewhere keept in XML files.

Could be, i don’t know. i’m not familiar with that part of the VS APIs. I’ll have someone else else have a look.

private void btnStartVS_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
EnvDTE80.DTE2 dte;
dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject(“VisualStudio.DTE.11.0”);

            sb.AppendLine(dte.FullName);

            Int32 i = dte.Solution.Count;

            UIHierarchy UIH = dte.ToolWindows.SolutionExplorer;
            UIHierarchyItems items = UIH.UIHierarchyItems;

            Int32 indent = 0;
            foreach (UIHierarchyItem uih in dte.ToolWindows.SolutionExplorer.UIHierarchyItems) 
            {
                displayItems(uih.UIHierarchyItems, sb, indent);
            }
            dte.ToolWindows.OutputWindow.ActivePane.OutputString(sb.ToString());

            try {
                Solution2 soln = (Solution2)dte.Solution;
                // show us the solution name
                string SolnName = System.IO.Path.GetFileNameWithoutExtension(soln.FullName);
/**
                MessageBox.Show("Adding a folder to the solution " + solnName);
                Project proj = soln.AddSolutionFolder("PL999");
                MessageBox.Show("Solution : " + solnName + " has " + soln.Projects.Count.ToString() + " projects");
**/
                Console.WriteLine("Solution : {0} has now {1} projects", SolnName, soln.Projects.Count.ToString());

                String ProjName = "IM00100851";
                String ProjPath = @"E:\Users\C770817\SW-PROJEKTE\Spezpla\"+ProjName;
                String ProjFullName = ProjPath + @"\" + ProjName + ".oxygene";
                Project proj = null;

                // lets find the project because if it is lready in soln ....
                Projects ps = soln.Projects;
                foreach (Project p in ps)
                {
                    if (ProjName.CompareTo(p.Name) == 0)
                    {
                        proj = p;
                    }
                }
                if (proj == null)
                {
                    // if proj == null add it the one or the other way
                    if (Directory.Exists(ProjPath) && (File.Exists(ProjFullName)))
                    {
                        // if path exits try to add from project file
                        Console.WriteLine("Project {0} seems to exist already, try adding it to solution {1}", 
                            ProjFullName, SolnName);
                        proj = soln.AddFromFile(ProjFullName);
                        Console.WriteLine("Project {0} added to solution {1}", 
                            ProjFullName, SolnName);
                    }
                    else
                    {
                        // if path does not exists make a new directory and add a project from a vstemplate
                        Console.WriteLine("Creating Directory {0}", ProjPath);
                        DirectoryInfo di = Directory.CreateDirectory(ProjPath);
                        Console.WriteLine("Directory {0} created!", ProjPath);
                        String TemplatePath = soln.GetProjectTemplate("Class Library", "Oxygene");
                        Console.WriteLine("Project {0} will be added to solution {1} from Template\n  {2}",
                            ProjName, SolnName, TemplatePath);
                        proj = soln.AddFromTemplate(TemplatePath, ProjPath, ProjName, false);
                        Console.WriteLine("Project {0} added to solution {1}", ProjName, SolnName);
                    }
                }
                Console.WriteLine("Solution : {0} has now {1} projects", SolnName, soln.Projects.Count.ToString());

                // lets find the project because AddFrom... does not return it
                ps = soln.Projects;
                foreach (Project p in ps)
                {
                    if (ProjName.CompareTo(p.Name) == 0) 
                    {
                        proj = p;
                    }
                }
                if (proj==null) 
                {
                    // if it remains null it was not found or not created in solution
                    Console.WriteLine("Project {0} not found in Solution {1}", ProjName, SolnName);
                    return;
                }
                // now lets attempt to add an existing code file to the project
                String vmsSourceFile = @"E:\Users\C770817\SW-PROJEKTE\Spezpla\Pas2Oxygene\PL999.PAS";
                ProjectItem pi = proj.ProjectItems.AddFromFileCopy(vmsSourceFile);

                foreach (Property p in pi.Properties)
                {
                    if ("BuildAction".CompareTo(p.Name)==0)
                    {
                        p.Value = 2;
                    }
                    if ("ExcludeFromBuild".CompareTo(p.Name) == 0)
                    {
                        p.Value = true;
                    }
                    Console.WriteLine("Property.Name: {0}  .Value: {1}", p.Name, p.Value);

                }
                
                // if it was found, for now, ask user to remove it from solution
                DialogResult yesno = MessageBox.Show("Shall we Remove the project from the Solution?","QUESTION",
                    MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
                if ( yesno==DialogResult.Yes )
                {
                    Console.WriteLine("Project {0} will be removed from solution {1}", proj.Name, SolnName);
                    soln.Remove(proj);
                    Console.WriteLine("Project {0} removed from solution {1}", ProjName, SolnName);
                }
                Console.WriteLine("Solution : {0} has now {1} projects", SolnName, soln.Projects.Count.ToString());
            }
            catch (SystemException ex)
            {
                Console.WriteLine("ERROR: {0}\n  {1}", ex.Message, ex.StackTrace.ToString());
            }
        }

        private void displayItems(UIHierarchyItems uih, StringBuilder sb, Int32 indent)
        {
            indent = indent + 2;
            foreach (UIHierarchyItem id in uih) 
            {
                String ins = new String(' ', indent);
                sb.AppendLine(ins+id.Name);
                if (id.Name.CompareTo("Form1.cs") == 0) 
                {
                    MessageBox.Show(id.Name);
                }
                displayItems(id.UIHierarchyItems, sb, 2);
            }
            indent = indent - 2;
        }

No this is the code (included above) used so far to change two properties;

        foreach (Property p in pi.Properties)
        {
            if ("BuildAction".CompareTo(p.Name)==0)
            {
                p.Value = 2;
            }
            if ("ExcludeFromBuild".CompareTo(p.Name) == 0)
            {
                p.Value = true;
            }
            Console.WriteLine("Property.Name: {0}  .Value: {1}", p.Name, p.Value);

        }

What I dont know is why I can not see any of the projects properties named as seen in the oxygene project file (xml file)

what I see from a code run such as above is:

Property.Name: IsLink  .Value: False
'WCFSpezplaServiceClient.vshost.exe' (Managed (v4.0.30319)): Loaded 'Anonymously Hosted DynamicMethods Assembly'
Property.Name: SubType  .Value: Code
Property.Name: CopyToOutputDirectory  .Value: 0
Property.Name: DefaultNamespace  .Value: IM00100851
Property.Name: CopyDestination  .Value: Folder
Property.Name: DisableDesigner  .Value: False
Property.Name: ExcludeFromBuild  .Value: True
Property.Name: FullyQualifiedResourceName  .Value: True
Property.Name: CustomTool  .Value: 
Property.Name: CustomToolNamespace  .Value: 
Property.Name: BuildAction  .Value: 2
Property.Name: DateModified  .Value: 28.08.2014 11:47
Property.Name: IsDependentFile  .Value: False
Property.Name: ItemType  .Value: Content
Property.Name: URL  .Value: file:///E:\Users\C770817\SW-PROJEKTE\Spezpla\IM00100851\PL999.PAS
Property.Name: __id  .Value: PL999.PAS
Property.Name: BuildActionInternal  .Value: 2
Property.Name: FileName  .Value: PL999.PAS
Property.Name: FullPath  .Value: E:\Users\C770817\SW-PROJEKTE\Spezpla\IM00100851\PL999.PAS
Property.Name: Extension  .Value: .PAS
Property.Name: ExtenderCATID  .Value: {eb066e96-c58d-4b48-9a37-df90becf2d9b}
Property.Name: ExtenderNames  .Value: System.String[]
Property.Name: ServiceProvider  .Value: System.__ComObject
Solution : Spezpla has now 27 projects

don’t waste time I have found it ! was looking at the wrong property set. The property to look at can be seen that way:

        foreach (Property p in proj.Properties)
        {
            Console.WriteLine("Property.Name: {0}  .Value: {1}", p.Name, p.Value);
        }


Property.Name: OutputTypeEx  .Value: 2
Property.Name: IsCooperProject  .Value: False
Property.Name: IsAndroidProject  .Value: False
Property.Name: IsNougatProject  .Value: False
Property.Name: MacAppName  .Value: 
Property.Name: MacAppID  .Value: 
Property.Name: MacPackMode  .Value: 0
Property.Name: MacIconFile  .Value: 
Property.Name: MacMinMonoVer  .Value: 
Property.Name: ProjectFolder  .Value: E:\Users\C770817\SW-PROJEKTE\Spezpla\IM00100851
Property.Name: ProjectFile  .Value: IM00100851.oxygene
Property.Name: ElementsLanguageType  .Value: Oxygene
Property.Name: ElementsLanguageName  .Value: Oxygene
Property.Name: ElementsLanguage  .Value: 0
Property.Name: HydrogeneOnly  .Value: False
Property.Name: OxygeneOnly  .Value: True
Property.Name: Mode  .Value: 0
Property.Name: IsJavaMode  .Value: False
Property.Name: IsDotNetA first chance exception of type 'System.InvalidCastException' occurred in WCFSpezplaServiceClient.exe
Mode  .Value: True
Property.Name: IsNougatMode  .Value: False
Property.Name: IsMetroProject  .Value: False
Property.Name: ApplicationManifest  .Value: 
Property.Name: DelphiCompatibility  .Value: False
Property.Name: DelphiDivide  .Value: False
Property.Name: AllowGlobals  .Value: False
Property.Name: AllowLegacyWith  .Value: False
Property.Name: AllowLegacyCreate  .Value: False
Property.Name: AllowLegacyOutParams  .Value: False
Property.Name: AllowUnsafeCode  .Value: False
Property.Name: InternalAssemblyName  .Value: 
Property.Name: DefaultUses  .Value: 
Property.Name: TargetFramework  .Value: 262144
Property.Name: ProjectIDGuid  .Value: d27a92d2-f97e-4842-8df0-6104f9c0e5cd
1 Like