예제 #1
0
 public CsProjFile(string fileName) : this(fileName, MSBuildProject.LoadFrom(fileName))
 {
 }
        protected override void OnWriteProject(ProgressMonitor monitor, MSBuildProject msproject)
        {
            base.OnWriteProject(monitor, msproject);

            dotNetCoreMSBuildProject.WriteProject(msproject, Project.TargetFramework.Id);
        }
예제 #3
0
 internal protected override void OnReadProjectHeader(ProgressMonitor monitor, MSBuildProject msproject)
 {
     // Do not read the project header when re-evaluating to prevent the
     // ToolsVersion that was initially read from the project being changed.
     if (!Project.IsReevaluating)
     {
         msbuildSdkProject.ReadProjectHeader(msproject);
     }
     base.OnReadProjectHeader(monitor, msproject);
 }
예제 #4
0
        /// <summary>
        /// Creates a new CsProjFile in a folder relative to the solution folder
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="directory"></param>

        public static CsProjFile LoadFrom(string filename)
        {
            var project = MSBuildProject.LoadFrom(filename);

            return(new CsProjFile(filename, project));
        }
예제 #5
0
 internal protected virtual void OnWriteProject(ProgressMonitor monitor, MSBuildProject msproject)
 {
     next.OnWriteProject(monitor, msproject);
     msproject.GetGlobalPropertyGroup().WriteObjectProperties(this, GetType(), true);
     msproject.WriteExternalProjectProperties(this, GetType(), true);
 }
        /// <summary>
        /// This is the method that indexes the comments files
        /// </summary>
        /// <remarks>Rather than a partial build, we'll just index the comments files.</remarks>
        private IndexedCommentsCache IndexComments()
        {
            HashSet <string>     projectDictionary = new HashSet <string>();
            IndexedCommentsCache cache             = new IndexedCommentsCache(100);
            MSBuildProject       projRef;
            string lastSolution = null;

            // Index the framework comments based on the framework version in the project
            var reflectionDataDictionary = new ReflectionDataSetDictionary(new[] { currentProject.ComponentPath,
                                                                                   Path.GetDirectoryName(currentProject.Filename) });
            var frameworkReflectionData = reflectionDataDictionary.CoreFrameworkByTitle(
                currentProject.FrameworkVersion, true);

            if (frameworkReflectionData == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  "Unable to locate information for a framework version or its redirect: {0}",
                                                                  currentProject.FrameworkVersion));
            }

            foreach (var location in frameworkReflectionData.CommentsFileLocations(currentProject.Language))
            {
                indexTokenSource.Token.ThrowIfCancellationRequested();

                cache.IndexCommentsFiles(Path.GetDirectoryName(location), Path.GetFileName(location),
                                         false, null);
            }

            // Index the comments file documentation sources
            foreach (string file in currentProject.DocumentationSources.SelectMany(ds => ds.CommentsFiles))
            {
                indexTokenSource.Token.ThrowIfCancellationRequested();

                cache.IndexCommentsFiles(Path.GetDirectoryName(file), Path.GetFileName(file), false, null);
            }

            // Also, index the comments files in project documentation sources
            foreach (DocumentationSource ds in currentProject.DocumentationSources)
            {
                foreach (var sourceProject in ds.Projects(
                             !String.IsNullOrEmpty(ds.Configuration) ? ds.Configuration : currentProject.Configuration,
                             !String.IsNullOrEmpty(ds.Platform) ? ds.Platform : currentProject.Platform))
                {
                    indexTokenSource.Token.ThrowIfCancellationRequested();

                    // NOTE: This code should be similar to the code in BuildProcess.ValidateDocumentationSources!

                    // Solutions are followed by the projects that they contain
                    if (sourceProject.ProjectFileName.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
                    {
                        lastSolution = sourceProject.ProjectFileName;
                        continue;
                    }

                    // Ignore projects that we've already seen
                    if (projectDictionary.Add(sourceProject.ProjectFileName))
                    {
                        using (projRef = new MSBuildProject(sourceProject.ProjectFileName))
                        {
                            // Use the project file configuration and platform properties if they are set.  If
                            // not, use the documentation source values.  If they are not set, use the SHFB
                            // project settings.
                            projRef.SetConfiguration(
                                !String.IsNullOrEmpty(sourceProject.Configuration) ? sourceProject.Configuration :
                                !String.IsNullOrEmpty(ds.Configuration) ? ds.Configuration : currentProject.Configuration,
                                !String.IsNullOrEmpty(sourceProject.Platform) ? sourceProject.Platform :
                                !String.IsNullOrEmpty(ds.Platform) ? ds.Platform : currentProject.Platform,
                                currentProject.MSBuildOutDir, false);

                            // Add Visual Studio solution macros if necessary
                            if (lastSolution != null)
                            {
                                projRef.SetSolutionMacros(lastSolution);
                            }

                            if (!String.IsNullOrEmpty(projRef.XmlCommentsFile))
                            {
                                cache.IndexCommentsFiles(Path.GetDirectoryName(projRef.XmlCommentsFile),
                                                         Path.GetFileName(projRef.XmlCommentsFile), false, null);
                            }
                        }
                    }
                }
            }

            return(cache);
        }
예제 #7
0
        /// <summary>
        /// Deletes a specified configuration name.
        /// </summary>
        /// <param name="name">The name of the configuration to be deleted.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
        public virtual int DeleteCfgsOfCfgName(string name)
        {
            // We need to QE/QS the project file
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            if (name == null)
            {
                Debug.Fail(String.Format(CultureInfo.CurrentCulture, "Name of the configuration should not be null if you want to delete it from project: {0}", MSBuildProject.GetFullPath((this.project.BuildProject))));
                // The configuration " '$(Configuration)' ==  " does not exist, so technically the goal
                // is achieved so return S_OK
                return(VSConstants.S_OK);
            }

            var configGroups   = new List <ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups);
            var groupsToDelete = new List <ProjectPropertyGroupElement>();

            foreach (var config in configGroups)
            {
                var configCanonicalName = ConfigCanonicalName.OfCondition(config.Condition);
                if (configCanonicalName.MatchesConfigName(name))
                {
                    groupsToDelete.Add(config);
                    configurationsList.Remove(configCanonicalName);
                }
            }

            foreach (var group in groupsToDelete)
            {
                group.Parent.RemoveChild(group);
            }

            NotifyOnCfgNameDeleted(name);

            return(VSConstants.S_OK);
        }
			public ProperyGroupData (MSBuildProject project) : base (project)
			{
			}
예제 #9
0
 internal ProjectItemMetadata(MSBuildProject project)
 {
     this.project = project;
 }
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(Microsoft.Build.Evaluation.Project buildProject)
        {
            Build.Execution.ProjectInstance projectInstanceToSearchExpandedReferences = null;
            // if project uses implicitly expanded list of references,
            // evaluate ImplicitlyExpandTargetFramework target and collect all resolved 'ReferencePath' items
            // later we'll group them and create special reference nodes that represent assembly groupings
            if (ProjectMgr.ImplicitlyExpandTargetFramework)
            {
                var res = ProjectMgr.Build(MsBuildTarget.ImplicitlyExpandTargetFramework);
                if (res.IsSuccessful)
                {
                    projectInstanceToSearchExpandedReferences = res.ProjectInstance;
                }
            }

            // collect groupled framework references
            if (projectInstanceToSearchExpandedReferences != null)
            {
                // fetch all 'ReferencePath' items that were resolved from implicitly expanded references (metadata#ResolvedFrom = ImplicitlyExpandTargetFramework)
                var groupings =
                    projectInstanceToSearchExpandedReferences
                    .GetItems(ProjectFileConstants.ReferencePath)
                    .Where(item => string.Equals(item.GetMetadataValue(ProjectFileConstants.ResolvedFrom), MsBuildTarget.ImplicitlyExpandTargetFramework, StringComparison.OrdinalIgnoreCase))
                    .Select(
                        item =>
                        new
                {
                    referenceGroupingDisplayName = item.GetMetadataValue("ReferenceGroupingDisplayName"),
                    referenceGrouping            = item.GetMetadataValue("ReferenceGrouping"),
                    file = item.EvaluatedInclude
                }
                        )
                    .Where(r =>
                           !string.IsNullOrEmpty(r.referenceGrouping) &&
                           !string.IsNullOrEmpty(r.referenceGroupingDisplayName) &&
                           !string.IsNullOrEmpty(r.file) &&
                           File.Exists(r.file)
                           )
                    .GroupBy(r => r.referenceGrouping);

                foreach (var grouping in groupings)
                {
                    var version = ParseVersionFromReferenceGrouping(grouping.Key);
                    if (version == null)
                    {
                        continue;
                    }
                    // pick property values from the first item - they should be the same for all elements in the grouping
                    var first        = grouping.First();
                    var groupedFiles = grouping.Select(x => x.file).ToArray();

                    var versonText = string.Format(
                        "{0}.{1}.{2}.{3}",
                        version.Major,
                        version.Minor,
                        version.Build != -1 ? version.Build : 0,
                        version.Revision != -1 ? version.Revision : 0
                        );

                    var node = new GroupingReferenceNode(ProjectMgr, first.referenceGroupingDisplayName, first.referenceGrouping, Path.GetDirectoryName(first.file), versonText, groupedFiles);
                    AddChild(node);
                }
            }

            BuildResult buildResult = this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences);

            foreach (string referenceType in SupportedReferenceTypes)
            {
                bool isAssemblyReference = referenceType == ProjectFileConstants.Reference;
                if (isAssemblyReference && !buildResult.IsSuccessful)
                {
                    continue;
                }

                foreach (var item in MSBuildProject.GetItems(buildProject, referenceType))
                {
                    ProjectElement element = new ProjectElement(this.ProjectMgr, item, false);

                    ReferenceNode node = CreateReferenceNode(referenceType, element, buildResult);
                    if (node != null)
                    {
                        this.AddChild(node);
                    }
                    if (isAssemblyReference)
                    {
                        ProjectMgr.UpdateValueOfCanUseTargetFSharpCoreReferencePropertyIfNecessary(node);
                    }
                }
            }
        }
예제 #11
0
        void IProject.Serialize()
        {
            System.Xml.XmlDocument xmlDocument = null;
            try
            {
                var projectLocationUri = new System.Uri(this.PathName, System.UriKind.RelativeOrAbsolute);

                xmlDocument = new System.Xml.XmlDocument();

                xmlDocument.AppendChild(xmlDocument.CreateComment("Automatically generated by BuildAMation v" + Bam.Core.State.VersionString));

                // TODO: this needs to be from the Toolset
                var versionString = DotNetFramework.DotNet.VersionString;
                var project = new MSBuildProject(xmlDocument, versionString);

                var generalGroup = project.CreatePropertyGroup();
                generalGroup.CreateProperty("ProjectGuid", this.ProjectGuid.ToString("B").ToUpper());
                // default configuration and platform
                {
                    var defaultConfiguration = generalGroup.CreateProperty("Configuration", "Debug");
                    defaultConfiguration.Condition = " '$(Configuration)' == '' ";
                }
                {
                    var defaultPlatform = generalGroup.CreateProperty("Platform", "AnyCPU");
                    defaultPlatform.Condition = " '$(Platform)' == '' ";
                }
                generalGroup.CreateProperty("TargetFrameworkVersion", "v" + versionString);

                // configurations
                // TODO: convert to var
                foreach (ProjectConfiguration configuration in this.ProjectConfigurations)
                {
                    configuration.SerializeCSBuild(project, projectLocationUri);
                }

                // source files
                if (this.SourceFileCollection.Count > 0)
                {
                    this.SourceFileCollection.SerializeCSBuild(project, projectLocationUri, this.PackageUri);
                }

                // application definition and page files
                if ((this.ApplicationDefinitionFile != null) ||
                    (this.PageFiles.Count > 0))
                {
                    var applicationDefinitionGroup = project.CreateItemGroup();

                    // application definition
                    if (this.ApplicationDefinitionFile != null)
                    {
                        var xamlRelativePath = Bam.Core.RelativePathUtilities.GetPath(this.ApplicationDefinitionFile.RelativePath, projectLocationUri);

                        var applicationDefinition = applicationDefinitionGroup.CreateItem("ApplicationDefinition", xamlRelativePath);
                        applicationDefinition.CreateMetaData("Generator", "MSBuild:Compile");
                        applicationDefinition.CreateMetaData("SubType", "Designer");

                        var sourcePathname = xamlRelativePath + ".cs";
                        var associatedSource = applicationDefinitionGroup.CreateItem("Compile", sourcePathname);
                        associatedSource.CreateMetaData("DependentUpon", System.IO.Path.GetFileName(xamlRelativePath));
                        associatedSource.CreateMetaData("SubType", "Code");
                    }

                    // page files
                    // TODO: convert to var
                    foreach (ProjectFile pageFile in this.PageFiles)
                    {
                        var xamlRelativePath = Bam.Core.RelativePathUtilities.GetPath(pageFile.RelativePath, projectLocationUri);

                        var applicationDefinition = applicationDefinitionGroup.CreateItem("Page", xamlRelativePath);
                        applicationDefinition.CreateMetaData("Generator", "MSBuild:Compile");
                        applicationDefinition.CreateMetaData("SubType", "Designer");

                        var sourcePathname = xamlRelativePath + ".cs";
                        var associatedSource = applicationDefinitionGroup.CreateItem("Compile", sourcePathname);
                        associatedSource.CreateMetaData("DependentUpon", System.IO.Path.GetFileName(xamlRelativePath));
                        associatedSource.CreateMetaData("SubType", "Code");
                    }
                }

                // project dependencies
                if (this.DependentProjectList.Count > 0)
                {
                    var dependencyItemGroup = project.CreateItemGroup();
                    foreach (var dependentProject in this.DependentProjectList)
                    {
                        var relativePath = Bam.Core.RelativePathUtilities.GetPath(dependentProject.PathName, this.PathName);
                        var projectReference = dependencyItemGroup.CreateItem("ProjectReference", relativePath);
                        projectReference.CreateMetaData("Project", dependentProject.Guid.ToString("B").ToUpper());
                        projectReference.CreateMetaData("Name", dependentProject.Name);
                    }
                }

                // project references
                if (this.ReferencesList.Count > 0)
                {
                    var referenceItemGroup = project.CreateItemGroup();
                    foreach (var reference in this.ReferencesList)
                    {
                        var noExtReference = reference;
                        if (noExtReference.EndsWith(".dll"))
                        {
                            noExtReference = reference.Remove(noExtReference.Length - 4);
                        }
                        referenceItemGroup.CreateItem("Reference", noExtReference);
                    }
                }

                // import C# project props
                project.CreateImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets");
            }
            catch (Bam.Core.Exception exception)
            {
                var message = System.String.Format("Xml construction error from project '{0}'", this.PathName);
                throw new Bam.Core.Exception(message, exception);
            }

            // write XML to disk
            System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(this.PathName));

            var xmlWriterSettings = new System.Xml.XmlWriterSettings();
            xmlWriterSettings.Indent = true;
            xmlWriterSettings.CloseOutput = true;
            xmlWriterSettings.OmitXmlDeclaration = false;
            xmlWriterSettings.NewLineOnAttributes = false;

            try
            {
                using (var xmlWriter = System.Xml.XmlWriter.Create(this.PathName, xmlWriterSettings))
                {
                    xmlDocument.Save(xmlWriter);
                    xmlWriter.WriteWhitespace(xmlWriterSettings.NewLineChars);
                }
            }
            catch (Bam.Core.Exception exception)
            {
                var message = System.String.Format("Serialization error from project '{0}'", this.PathName);
                throw new Bam.Core.Exception(message, exception);
            }
        }
			public ItemData (MSBuildProject project, string name, string include, string unevaluatedInclude): base (project)
			{
				this.name = name;
				this.include = include;
				this.unevaluatedInclude = unevaluatedInclude;
			}
			public ItemGroupData (MSBuildProject project): base (project)
			{
			}
예제 #14
0
        protected override void OnWriteProject(ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject)
        {
            if (projItemsPath == FilePath.Null)
            {
                projItemsPath = Path.ChangeExtension(FileName, ".projitems");
            }

            if (projitemsProject == null)
            {
                projitemsProject          = new MSBuildProject(msproject.EngineManager);
                projitemsProject.FileName = projItemsPath;
                var grp = projitemsProject.GetGlobalPropertyGroup();
                if (grp == null)
                {
                    grp = projitemsProject.AddNewPropertyGroup(false);
                }
                grp.SetValue("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)");
                grp.SetValue("HasSharedItems", true);
                grp.SetValue("SharedGUID", ItemId, preserveExistingCase: true);
            }

            IMSBuildPropertySet configGrp = projitemsProject.PropertyGroups.FirstOrDefault(g => g.Label == "Configuration");

            if (configGrp == null)
            {
                configGrp       = projitemsProject.AddNewPropertyGroup(true);
                configGrp.Label = "Configuration";
            }
            configGrp.SetValue("Import_RootNamespace", DefaultNamespace);

            base.OnWriteProject(monitor, msproject);

            var newProject = FileName == null || !File.Exists(FileName);

            if (newProject)
            {
                var grp = msproject.GetGlobalPropertyGroup();
                if (grp == null)
                {
                    grp = msproject.AddNewPropertyGroup(false);
                }
                grp.SetValue("ProjectGuid", ItemId, preserveExistingCase: true);
                var import = msproject.AddNewImport(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props");
                import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')";
                msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props");
                msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props");
                import       = msproject.AddNewImport(Path.ChangeExtension(FileName.FileName, ".projitems"));
                import.Label = "Shared";
                if (LanguageName.Equals("C#", StringComparison.OrdinalIgnoreCase))
                {
                    msproject.AddNewImport(CSharptargets);
                }
                else if (LanguageName.Equals("F#", StringComparison.OrdinalIgnoreCase))
                {
                    msproject.AddNewImport(FSharptargets);
                }
            }
            else
            {
                msproject.Load(FileName);
            }

            // having no ToolsVersion is equivalent to 2.0, roundtrip that correctly
            if (ToolsVersion != "2.0")
            {
                msproject.ToolsVersion = ToolsVersion;
            }
            else if (string.IsNullOrEmpty(msproject.ToolsVersion))
            {
                msproject.ToolsVersion = null;
            }
            else
            {
                msproject.ToolsVersion = "2.0";
            }

            projitemsProject.Save(projItemsPath);
        }
예제 #15
0
        /// <summary>
        ///     Re-scan referenced packages for the current project.
        /// </summary>
        /// <param name="cancellationToken">
        ///     An optional <see cref="CancellationToken"/> that can be used to cancel the operation.
        /// </param>
        /// <returns>
        ///     <c>true</c>, if the package references were successfully scanned and updated; otherwise, <c>false</c>.
        /// </returns>
        public virtual async Task <bool> UpdatePackageReferences(CancellationToken cancellationToken = default)
        {
            try
            {
                _referencedPackageVersions.Clear();

                if (!HasMSBuildProject)
                {
                    Log.Debug("Not scanning package references (although existing references have been cleared) for MSBuild project {ProjectFileName} because the project is not currently loaded.", ProjectFile.FullName);

                    return(false);
                }

                Dictionary <string, SemanticVersion> referencedPackageVersions = await MSBuildProject.GetReferencedPackageVersions(cancellationToken);

                _referencedPackageVersions.AddRange(referencedPackageVersions);

                return(true);
            }
            catch (Exception packageReferenceUpdateError)
            {
                Log.Error(packageReferenceUpdateError, "Error scanning NuGet package references for MSBuild project '{ProjectFileName}'.", ProjectFile.FullName);

                return(false);
            }
        }
        static bool UpgradeMonoGameProject(MonoDevelop.Core.IProgressMonitor monitor, MonoDevelop.Projects.SolutionEntityItem item, MSBuildProject project)
        {
            bool needsSave    = false;
            bool containsMGCB = project.ItemGroups.Any(x => x.Items.Any(i => System.IO.Path.GetExtension(i.Include) == ".mgcb"));
            bool isMonoGame   = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) ||
                                project.ItemGroups.Any(x => x.Items.Any(i => i.Name == "Reference" && i.Include == "MonoGame.Framework")) ||
                                containsMGCB;
            bool isApplication = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "OutputType" && p.GetValue() == "Exe")) ||
                                 project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "AndroidApplication" && string.Compare(p.GetValue(), bool.TrueString, true) == 0));
            bool isShared = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "HasSharedItems" && p.GetValue() == "true"));
            var  type     = item.GetType().Name;

            monitor.Log.WriteLine("Found {0}", type);
            var platform = Environment.OSVersion.Platform == PlatformID.Win32NT ? "Windows" : "DesktopGL";
            var path     = MonoGameExtensionsPath;

            switch (type)
            {
            case "XamarinIOSProject":
                platform = "iOS";
                break;

            case "MonoDroidProject":
                platform = "Android";
                break;

            case "XamMac2Project":
            case "MonoGameProject":
                platform = "DesktopGL";
                break;

            case "XamMac":
            case "XamMacProject":
                platform = "DesktopGL";
                // Xamarin.Mac Classic does not use MSBuild so we need to absolute path.
                path = MonoGameExtensionsAbsolutePath;
                break;

            case "MonoMac":
            case "MonoMacProject":
                platform = "MacOSX";
                // Xamarin.Mac Classic does not use MSBuild so we need to absolute path.
                path = MonoGameExtensionsAbsolutePath;
                break;
            }
            monitor.Log.WriteLine("Platform = {0}", platform);
            monitor.Log.WriteLine("Path = {0}", path);
            monitor.Log.WriteLine("isMonoGame {0}", isMonoGame);
            if (isMonoGame)
            {
                var ritems = new List <MSBuildItem> ();
                foreach (var ig in project.ItemGroups)
                {
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "MonoGame.Framework"))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "MonoGame.Framework.dll"));
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "Tao.Sdl"))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be Tao.Sdl", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "Tao.Sdl.dll"));
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include.StartsWith("OpenTK") &&
                                                     (platform != "iOS" && platform != "Android")))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be OpenTK", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "OpenTK.dll"));
                            a.SetMetadata("SpecificVersion", "true");
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "NVorbis"))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be NVorbis", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "NVorbis.dll"));
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                }
                foreach (var a in ritems)
                {
                    project.RemoveItem(a);
                }
                var dotNetProject = item as DotNetProject;
                if (dotNetProject != null && (type == "MonoMacProject" || type == "XamMacProject"))
                {
                    var items    = new List <ProjectReference> ();
                    var newitems = new List <ProjectReference> ();
                    foreach (var reference in dotNetProject.References)
                    {
                        if (reference.Reference == "MonoGame.Framework" && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "MonoGame.Framework.dll")));
                        }
                        if (reference.Reference.StartsWith("OpenTK") && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "OpenTK.dll")));
                        }
                        if (reference.Reference == "NVorbis" && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "NVorbis.dll")));
                        }
                        if (reference.Reference == "Tao.Sdl" && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "Tao.Sdl.dll")));
                        }
                    }
                    dotNetProject.References.RemoveRange(items);
                    dotNetProject.References.AddRange(newitems);
                }
            }
            if (isMonoGame && containsMGCB && (isApplication || isShared))
            {
                if (!project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) && !isShared)
                {
                    monitor.Log.WriteLine("Adding MonoGamePlatform", platform);
                    project.PropertyGroups.First().SetPropertyValue("MonoGamePlatform", platform, true);
                    needsSave = true;
                }
                if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameCommonProps, StringComparison.OrdinalIgnoreCase)) && !isShared)
                {
                    monitor.Log.WriteLine("Adding MonoGame.Common.props Import");
                    var e       = project.Document.DocumentElement;
                    var manager = new XmlNamespaceManager(new NameTable());
                    var schema  = "http://schemas.microsoft.com/developer/msbuild/2003";
                    manager.AddNamespace("tns", schema);
                    var import = project.Document.CreateElement("Import", schema);
                    import.SetAttribute("Project", MonoGameCommonProps);
                    import.SetAttribute("Condition", string.Format("Exists('{0}')", MonoGameCommonProps));
                    project.Document.DocumentElement.InsertBefore(import, project.Document.DocumentElement.FirstChild);
                    needsSave = true;
                }
                if (containsMGCB)
                {
                    var ritems = new List <MSBuildItem> ();
                    foreach (var ig in project.ItemGroups)
                    {
                        foreach (var i in ig.Items.Where(x => System.IO.Path.GetExtension(x.Include) == ".mgcb"))
                        {
                            if (i.Name != "MonoGameContentReference" && i.Name == "None")
                            {
                                monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include);
                                ig.AddNewItem("MonoGameContentReference", i.Include);
                                ritems.Add(i);
                                needsSave = true;
                            }
                        }
                    }
                    foreach (var a in ritems)
                    {
                        project.RemoveItem(a);
                    }
                }
                if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameContentBuildTargets, StringComparison.OrdinalIgnoreCase)) && !isShared)
                {
                    monitor.Log.WriteLine("Adding MonoGame Content Builder .targets");
                    project.AddNewImport(MonoGameContentBuildTargets);
                    needsSave = true;
                }
            }
            return(needsSave);
        }
예제 #17
0
        protected override MSBuildProject SaveProject(IProgressMonitor monitor)
        {
            MSBuildSerializer ser = CreateSerializer();

            ser.SerializationContext.BaseFile        = EntityItem.FileName;
            ser.SerializationContext.ProgressMonitor = monitor;

            MSBuildProject projitemsProject = new MSBuildProject();
            MSBuildProject msproject        = new MSBuildProject();

            var newProject = EntityItem.FileName == null || !File.Exists(EntityItem.FileName);

            if (newProject)
            {
                var grp = msproject.GetGlobalPropertyGroup();
                if (grp == null)
                {
                    grp = msproject.AddNewPropertyGroup(false);
                }
                grp.SetPropertyValue("ProjectGuid", EntityItem.ItemId, false);
                var import = msproject.AddNewImport(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props");
                import.Condition = @"Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')";
                msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props");
                msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props");
                import       = msproject.AddNewImport(Path.ChangeExtension(EntityItem.FileName.FileName, ".projitems"));
                import.Label = "Shared";
                msproject.AddNewImport(@"$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets");
            }
            else
            {
                msproject.Load(EntityItem.FileName);
            }

            // having no ToolsVersion is equivalent to 2.0, roundtrip that correctly
            if (ToolsVersion != "2.0")
            {
                msproject.ToolsVersion = ToolsVersion;
            }
            else if (string.IsNullOrEmpty(msproject.ToolsVersion))
            {
                msproject.ToolsVersion = null;
            }
            else
            {
                msproject.ToolsVersion = "2.0";
            }

            if (projitemsFile == null)
            {
                projitemsFile = ((SharedAssetsProject)Item).ProjItemsPath;
            }
            if (File.Exists(projitemsFile))
            {
                projitemsProject.Load(projitemsFile);
            }
            else
            {
                var grp = projitemsProject.AddNewPropertyGroup(true);
                grp.SetPropertyValue("MSBuildAllProjects", "$(MSBuildAllProjects);$(MSBuildThisFileFullPath)", false);
                grp.SetPropertyValue("HasSharedItems", "true", false);
                grp.SetPropertyValue("SharedGUID", EntityItem.ItemId, false);
            }

            var configGrp = projitemsProject.PropertyGroups.FirstOrDefault(g => g.Label == "Configuration");

            if (configGrp == null)
            {
                configGrp       = projitemsProject.AddNewPropertyGroup(true);
                configGrp.Label = "Configuration";
            }
            configGrp.SetPropertyValue("Import_RootNamespace", ((SharedAssetsProject)EntityItem).DefaultNamespace, false);

            SaveProjectItems(monitor, new MSBuildFileFormatVS12(), ser, projitemsProject, "$(MSBuildThisFileDirectory)");

            projitemsProject.Save(projitemsFile);

            return(msproject);
        }
예제 #18
0
 internal protected virtual void OnReadProject(ProgressMonitor monitor, MSBuildProject msproject)
 {
     next.OnReadProject(monitor, msproject);
     msproject.EvaluatedProperties.ReadObjectProperties(this, GetType(), true);
     msproject.ReadExternalProjectProperties(this, GetType(), true);
 }
예제 #19
0
 public override Task <bool> Migrate(ProjectLoadProgressMonitor monitor, MSBuildProject project, string fileName, string language)
 {
     project.RemoveProjectTypeGuid("{D049D6DC-2C66-40ED-8249-2DB930ACA0B4}");
     project.AddProjectTypeGuid("{466CB615-7798-440F-9326-B783655656F0}");
     return(Task.FromResult(MigrationResult));
 }
 public static void AddKnownItemAttributes(MSBuildProject project)
 {
     project.AddKnownItemAttribute("PackageReference", "Version");
 }
예제 #21
0
 public override Task <MigrationType> PromptForMigration(ProjectLoadProgressMonitor monitor, MSBuildProject project, string fileName, string language)
 {
     return(Task.FromResult(PromptForMigrationResult));
 }
예제 #22
0
        internal protected override void OnWriteProject(ProgressMonitor monitor, MSBuildProject msproject)
        {
            base.OnWriteProject(monitor, msproject);

            msbuildSdkProject.WriteProject(msproject, Project.TargetFramework.Id);
        }
예제 #23
0
        public void RebuildTest()
        {
            var csproj = BuildProject("MyReleaseBuild");

            var dsymDir = Path.GetFullPath(Path.Combine(AppBundlePath, "..", Path.GetFileName(AppBundlePath) + ".dSYM"));

            var timestamps     = Directory.EnumerateFiles(AppBundlePath, "*.*", SearchOption.AllDirectories).ToDictionary(file => file, file => GetLastModified(file));
            var dsymTimestamps = Directory.EnumerateFiles(dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary(file => file, file => GetLastModified(file));

            EnsureFilestampChange();

            // Rebuild w/ no changes
            BuildProject("MyReleaseBuild", clean: false);

            var newTimestamps     = Directory.EnumerateFiles(AppBundlePath, "*.*", SearchOption.AllDirectories).ToDictionary(file => file, file => GetLastModified(file));
            var newDSymTimestamps = Directory.EnumerateFiles(dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary(file => file, file => GetLastModified(file));

            foreach (var file in timestamps.Keys)
            {
                Assert.AreEqual(timestamps[file], newTimestamps[file], "#1: " + file);
            }

            foreach (var file in dsymTimestamps.Keys)
            {
                Assert.AreEqual(dsymTimestamps[file], newDSymTimestamps[file], "#2: " + file);
            }

            EnsureFilestampChange();

            // Rebuild after changing MtouchUseLlvm
            var proj = new MSBuildProject(csproj, this);

            proj.SetProperty("MtouchUseLlvm", "true");
            BuildProject("MyReleaseBuild", clean: false);

            newTimestamps     = Directory.EnumerateFiles(AppBundlePath, "*.*", SearchOption.AllDirectories).ToDictionary(file => file, file => GetLastModified(file));
            newDSymTimestamps = Directory.EnumerateFiles(dsymDir, "*.*", SearchOption.AllDirectories).ToDictionary(file => file, file => GetLastModified(file));

            foreach (var file in timestamps.Keys)
            {
                var fileName = Path.GetFileName(file);

                var isModificationExpected = false;

                if (fileName.EndsWith(".aotdata.armv7", StringComparison.Ordinal) || fileName.EndsWith(".aotdata.arm64", StringComparison.Ordinal))
                {
                    // aotdata files should be modified
                    isModificationExpected = true;
                }
                else if (fileName == "MyReleaseBuild")
                {
                    // the executable must of course be modified
                    isModificationExpected = true;
                }
                else if (fileName == "CodeResources")
                {
                    // the signature has of course changed too
                    isModificationExpected = true;
                }
                else if (fileName.EndsWith(".dll", StringComparison.Ordinal) || fileName.EndsWith(".exe", StringComparison.Ordinal))
                {
                    // I'm not sure if assemblies have to be modified, but they currently are, so mark them as such to make the test pass.
                    isModificationExpected = true;
                }

                if (isModificationExpected)
                {
                    Assert.AreNotEqual(timestamps[file], newTimestamps[file], "#3: " + file);
                }
                else
                {
                    Assert.AreEqual(timestamps[file], newTimestamps[file], "#3: " + file);
                }
            }

            foreach (var file in dsymTimestamps.Keys)
            {
                Assert.AreNotEqual(dsymTimestamps[file], newDSymTimestamps[file], "#4: " + file);
            }
        }
예제 #24
0
 protected override void OnWriteProject(ProgressMonitor monitor, MSBuildProject msproject)
 {
     UpdateProject(msproject);
     base.OnWriteProject(monitor, msproject);
 }
 protected override void OnPrepareForEvaluation(MSBuildProject project)
 {
     base.OnPrepareForEvaluation(project);
 }
예제 #26
0
 /// <summary>
 /// Creates a new class library project at the given filename
 /// and assembly name
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="assemblyName"></param>
 public static CsProjFile CreateAtLocation(string fileName, string assemblyName)
 {
     return(CreateCore(MSBuildProject.Create(assemblyName), fileName));
 }
예제 #27
0
 protected override void OnReadProjectHeader(ProgressMonitor monitor, MSBuildProject msproject)
 {
     dotNetCoreMSBuildProject.ReadProjectHeader(msproject);
     base.OnReadProjectHeader(monitor, msproject);
 }
예제 #28
0
 public CsProjFile(string fileName, MSBuildProject project)
 {
     _fileName = fileName;
     _project  = project;
 }
        /// <summary>
        /// Deletes a specified platform name.
        /// </summary>
        /// <param name="platName">The platform name to delete.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public virtual int DeleteCfgsOfPlatformName(string platName)
        {
            // We need to QE/QS the project file
            if (!this.ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            if (platName == null)
            {
                Debug.Fail(String.Format(CultureInfo.CurrentCulture, "Name of the platform should not be null if you want to delete it from project: {0}", MSBuildProject.GetFullPath((this.project.BuildProject))));
                return(VSConstants.S_OK);
            }

            this.project.BuildProject.ReevaluateIfNecessary();
            var configGroups   = new List <Microsoft.Build.Construction.ProjectPropertyGroupElement>(this.project.BuildProject.Xml.PropertyGroups);
            var groupsToDelete = new List <Microsoft.Build.Construction.ProjectPropertyGroupElement>();

            foreach (var config in configGroups)
            {
                var configCanonicalName = ConfigCanonicalName.OfCondition(config.Condition);
                if (configCanonicalName.MatchesPlatform(platName))
                {
                    groupsToDelete.Add(config);
                    configurationsList.Remove(configCanonicalName);
                }
            }

            foreach (var group in groupsToDelete)
            {
                group.Parent.RemoveChild(group);
            }

            NotifyOnPlatformNameDeleted(platName);

            return(VSConstants.S_OK);
        }
예제 #30
0
 internal override void SaveProjectItems(ProgressMonitor monitor, MSBuildProject msproject, HashSet <MSBuildItem> loadedItems, string pathPrefix)
 {
     // Save project items in the .projitems file
     base.SaveProjectItems(monitor, projitemsProject, usedMSBuildItems, "$(MSBuildThisFileDirectory)");
 }
예제 #31
0
 /// <summary>
 /// Called just after the MSBuild project is loaded but before it is evaluated.
 /// </summary>
 /// <param name="project">The project</param>
 /// <remarks>
 /// Subclasses can override this method to transform the MSBuild project before it is evaluated.
 /// For example, it can be used to add or remove imports, or to set custom values for properties.
 /// Changes done in the MSBuild files are not saved.
 /// </remarks>
 internal protected virtual void OnPrepareForEvaluation(MSBuildProject project)
 {
     next.OnPrepareForEvaluation(project);
 }
 void CreateMSBuildProject(string xml)
 {
     msbuildProject = new MSBuildProject();
     msbuildProject.LoadXml(xml);
 }
예제 #33
0
 internal protected virtual void OnReadProjectHeader(ProgressMonitor monitor, MSBuildProject msproject)
 {
     next.OnReadProjectHeader(monitor, msproject);
 }
        public override void SaveProject(MonoDevelop.Core.IProgressMonitor monitor, MonoDevelop.Projects.SolutionEntityItem item, MSBuildProject project)
        {
            var changed = UpgradeMonoGameProject(monitor, item, project);

            base.SaveProject(monitor, item, project);
            if (changed)
            {
                this.LoadProject(monitor, item, project);
            }
        }
			public PropertyData (string name, MSBuildProject project) : base (project)
			{
				this.name = name;
			}