예제 #1
0
        public static bool UpgradeProjectProperties(Microsoft.Build.Evaluation.Project project, bool cpp)
        {
            bool modified = false;

            string outputDir       = null;
            string headerOutputDir = null;
            string baseDirectoryForGeneratedInclude = null;

            string value = project.GetProperty(PropertyNames.Old.OutputDir, false);

            if (!string.IsNullOrEmpty(value))
            {
                project.RemovePropertyWithName(PropertyNames.Old.OutputDir);
                value = value.Replace("$(IceBuilder", "%(");
                project.SetItemMetadata(ItemMetadataNames.OutputDir, value);
                modified  = true;
                outputDir = value;
            }
            else if (cpp)
            {
                // The default output directory for C++ generated items was changed to $(IntDir)
                // but we keep the old default when converted projects by setting it in the project
                // file
                project.SetItemMetadata(ItemMetadataNames.OutputDir, "generated");
                outputDir = "generated";
            }

            value = project.GetProperty(PropertyNames.Old.IncludeDirectories, false);
            if (!string.IsNullOrEmpty(value))
            {
                project.RemovePropertyWithName(PropertyNames.Old.IncludeDirectories);
                value = value.Replace("$(IceHome)\\slice", "");
                value = value.Replace("$(IceHome)/slice", "");
                value = value.Trim(';');
                value = value.Replace("$(IceBuilder", "%(");
                if (!string.IsNullOrEmpty(value))
                {
                    project.SetItemMetadata(ItemMetadataNames.IncludeDirectories, value);
                }
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.HeaderOutputDir, false);
            if (!string.IsNullOrEmpty(value))
            {
                project.RemovePropertyWithName(PropertyNames.Old.HeaderOutputDir);
                value = value.Replace("$(IceBuilder", "%(");
                project.SetItemMetadata(ItemMetadataNames.HeaderOutputDir, value);
                modified        = true;
                headerOutputDir = value;
            }

            value = project.GetProperty(PropertyNames.Old.HeaderExt, false);
            if (!string.IsNullOrEmpty(value))
            {
                project.RemovePropertyWithName(PropertyNames.Old.HeaderExt);
                project.SetItemMetadata(ItemMetadataNames.HeaderExt, value);
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.BaseDirectoryForGeneratedInclude, false);
            if (!string.IsNullOrEmpty(value))
            {
                project.RemovePropertyWithName(PropertyNames.Old.BaseDirectoryForGeneratedInclude);
                project.SetItemMetadata(ItemMetadataNames.BaseDirectoryForGeneratedInclude, value);
                modified = true;
                baseDirectoryForGeneratedInclude = value;
            }

            value = project.GetProperty(PropertyNames.Old.SourceExt, false);
            if (!string.IsNullOrEmpty(value))
            {
                project.RemovePropertyWithName(PropertyNames.Old.SourceExt);
                project.SetItemMetadata(ItemMetadataNames.SourceExt, value);
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.AllowIcePrefix, false);
            string additionalOptions = project.GetProperty(PropertyNames.Old.AdditionalOptions, false);

            if (!string.IsNullOrEmpty(additionalOptions))
            {
                project.RemovePropertyWithName(PropertyNames.Old.AdditionalOptions);
                modified = true;
            }

            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) ||
                    value.Equals("true", StringComparison.CurrentCultureIgnoreCase))
                {
                    additionalOptions = String.Format("{0} --ice", additionalOptions).Trim();
                }
                project.RemovePropertyWithName(PropertyNames.Old.AllowIcePrefix);
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.Underscore, false);
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) ||
                    value.Equals("true", StringComparison.CurrentCultureIgnoreCase))
                {
                    additionalOptions = String.Format("{0} --underscore", additionalOptions).Trim();
                }
                project.RemovePropertyWithName(PropertyNames.Old.Underscore);
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.Stream, false);
            if (!string.IsNullOrEmpty(value))
            {
                if (value.Equals("yes", StringComparison.CurrentCultureIgnoreCase) ||
                    value.Equals("true", StringComparison.CurrentCultureIgnoreCase))
                {
                    additionalOptions = String.Format("{0} --stream ", additionalOptions).Trim();
                }
                project.RemovePropertyWithName(PropertyNames.Old.Stream);
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.DLLExport, false);
            if (!string.IsNullOrEmpty(value))
            {
                additionalOptions = String.Format("{0} --dll-export {1}", additionalOptions, value).Trim();
                project.RemovePropertyWithName(PropertyNames.Old.DLLExport);
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.Checksum, false);
            if (!string.IsNullOrEmpty(value))
            {
                additionalOptions = String.Format("{0} --checksum", additionalOptions).Trim();
                project.RemovePropertyWithName(PropertyNames.Old.Checksum);
                modified = true;
            }

            value = project.GetProperty(PropertyNames.Old.Tie, false);
            if (!string.IsNullOrEmpty(value))
            {
                additionalOptions = String.Format("{0} --tie", additionalOptions).Trim();
                project.RemovePropertyWithName(PropertyNames.Old.Tie);
                modified = true;
            }

            if (!string.IsNullOrEmpty(additionalOptions))
            {
                additionalOptions = additionalOptions.Replace("IceBuilder", "SliceCompile");
                project.SetItemMetadata(ItemMetadataNames.AdditionalOptions, additionalOptions);
            }

            if (string.IsNullOrEmpty(baseDirectoryForGeneratedInclude))
            {
                if (!string.IsNullOrEmpty(headerOutputDir))
                {
                    project.SetClCompileAdditionalIncludeDirectories(headerOutputDir);
                }
                else
                {
                    project.SetClCompileAdditionalIncludeDirectories(outputDir);
                }
            }

            value = project.GetProperty("ProjectTypeGuids", false);
            if (!string.IsNullOrEmpty(value))
            {
                value = value.Replace(Package.IceBuilderOldFlavor, Package.IceBuilderNewFlavor);
                project.SetProperty("ProjectTypeGuids", value, "");
                modified = true;
            }

            return(modified);
        }