private void AddFinalPropertiesAndImports()

in src/Deprecated/Conversion/ProjectFileConverter.cs [1694:1816]


        private void AddFinalPropertiesAndImports(XmlElementWithLocation languageElement, bool isTriumphProject)
        {
            // For the main project file only, add a line at the end of the new XMake
            // project file to import the appropriate .TARGETS file.
            if (!this.isUserFile)
            {
                // We set a property called "FileUpgradeFlags", so that for command-line conversions,
                // if this project is ever loaded into the IDE, the file upgrade (.VB code, etc.) will kick in.
                // The "20" means SxS upgrade.  For IDE conversions, the project system will itself set
                // this property immediately after the MSBuild conversion returns, so this value will
                // be overwritten.
                this.globalPropertyGroup.AddProperty(XMakeProjectStrings.fileUpgradeFlags, "20");

                // VisualBasic projects need MyType set.
                if
                (
                    (
                        (this.language == VSProjectElements.visualBasic) ||
                        (
                            (this.language == VSProjectElements.EVisualBasic) &&
                            (this.frameworkVersionForVSD == XMakeProjectStrings.vTwo)
                        )
                    ) &&
                    (!this.isMyTypeAlreadySetInOriginalProject) &&
                    !isTriumphProject        // Doesn't apply to Triumph->Trinity conversions.
                )
                {
                    if (this.outputType != null && this.outputType.Length > 0)
                    {
                        if (String.Compare(this.outputType, XMakeProjectStrings.winExe, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            if (this.hasWindowsFormsReference)
                            {
                                // Only applies if there's a System.Windows.Forms reference.
                                this.globalPropertyGroup.AddProperty(XMakeProjectStrings.myType, XMakeProjectStrings.windowsFormsWithCustomSubMain);
                            }
                            else
                            {
                                this.globalPropertyGroup.AddProperty(XMakeProjectStrings.myType, XMakeProjectStrings.console);
                            }
                        }
                        else if (String.Compare(this.outputType, XMakeProjectStrings.exe, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.globalPropertyGroup.AddProperty(XMakeProjectStrings.myType, XMakeProjectStrings.console);
                        }
                        else if (String.Compare(this.outputType, XMakeProjectStrings.library, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            this.globalPropertyGroup.AddProperty(XMakeProjectStrings.myType, XMakeProjectStrings.windows);
                        }
                    }
                }
                else if (this.language == VSProjectElements.EVisualBasic)
                {
                    // For Devices, we always want a MyType of "Empty," as projects
                    //   are converted into v1 .NETCF, which doesn't support My.NET
                    this.globalPropertyGroup.AddProperty(XMakeProjectStrings.myType, XMakeProjectStrings.empty);
                }

                // We need to handle the SDE scenarios for C# and VB
                if (languageElement.Name == VSProjectElements.ECSharp)
                {
                    xmakeProject.AddImport(XMakeProjectStrings.importPrefix + XMakeProjectStrings.SDECSTargets);
                }
                else if (languageElement.Name == VSProjectElements.EVisualBasic)
                {
                    xmakeProject.AddImport(XMakeProjectStrings.importPrefix + XMakeProjectStrings.SDEVBTargets);
                }
                else if (languageElement.Name == VSProjectElements.cSharp)
                {
                    xmakeProject.AddImport(XMakeProjectStrings.importPrefix + XMakeProjectStrings.targetsFilenamePrefix + XMakeProjectStrings.csharpTargets + XMakeProjectStrings.importSuffix);
                }
                else if (languageElement.Name == VSProjectElements.visualBasic)
                {
                    xmakeProject.AddImport(XMakeProjectStrings.importPrefix + XMakeProjectStrings.targetsFilenamePrefix + XMakeProjectStrings.visualBasicTargets + XMakeProjectStrings.importSuffix);
                }
                else if (languageElement.Name == VSProjectElements.visualJSharp)
                {
                    xmakeProject.AddImport(XMakeProjectStrings.importPrefix + XMakeProjectStrings.targetsFilenamePrefix + XMakeProjectStrings.visualJSharpTargets + XMakeProjectStrings.importSuffix);
                }
                else
                {
                    xmakeProject.AddImport(XMakeProjectStrings.importPrefix + XMakeProjectStrings.targetsFilenamePrefix + languageElement.Name + XMakeProjectStrings.importSuffix);
                }

                // [ancrider] VSTO project migration will handle the import target changes.
                //if (isTriumphProject)
                //{
                //    xmakeProject.AddImport(XMakeProjectStrings.triumphImport, null);
                //}

                // Also add the PreBuildEvent and PostBuildEvent properties to the end
                // of the project file.  The reason is that they can contain embedded
                // macros that are defined in the .TARGETS file that was imported
                // above.
                if ((this.preBuildEvent != null) || (this.postBuildEvent != null))
                {
                    // In this case, we specifically need the property group at the end, so we can't just call AddPropertyGroup(..),
                    // but instead must do it ourselves
                    ProjectPropertyGroupElement preAndPostBuildEvents = xmakeProject.CreatePropertyGroupElement();
                    xmakeProject.AppendChild(preAndPostBuildEvents);

                    // Add the "PreBuildEvent" property.
                    if (this.preBuildEvent != null)
                    {
                        // We must escape the percent-sign in order to handle cases like
                        // "echo %DEBUGGER%".  We don't want MSBuild to treat the "%DE" as
                        // an escaped character.
                        preAndPostBuildEvents.AddProperty(VSProjectAttributes.preBuildEvent,
                            this.preBuildEvent.Replace("%", "%25"));
                    }

                    // Add the "PostBuildEvent" property.
                    if (this.postBuildEvent != null)
                    {
                        // We must escape the percent-sign in order to handle cases like
                        // "echo %DEBUGGER%".  We don't want MSBuild to treat the "%DE" as
                        // an escaped character.
                        preAndPostBuildEvents.AddProperty(VSProjectAttributes.postBuildEvent,
                            this.postBuildEvent.Replace("%", "%25"));
                    }
                }
            }
        }