Beispiel #1
0
 internal static void AddSyncedProject(VSHelpers.Projects.ProjectBase vsp)
 {
     mSyncedProjects.Add(vsp);
     PluginManager.ReactToSyncedProjectLoad(vsp);
 }
Beispiel #2
0
 public override void SyncTo(ProjectBase projectBase, bool performTranslation)
 {
     throw new NotImplementedException();
 }
Beispiel #3
0
 internal static void RemoveSyncedProject(VSHelpers.Projects.ProjectBase project)
 {
     mSyncedProjects.Remove(project);
 }
        private bool IsContentFile(ProjectItem bi, ProjectBase containingProject)
        {
            bool shouldSkipContent = false;

            if (bi.ItemType == "Folder" || bi.ItemType == "_DebugSymbolsOutputPath" || bi.ItemType == "Reference")
            {
                // Skip trying to add the folder.  We don't need to do this because if it
                // contains anything, then the contained objects will automatically put themselves in a folder
                shouldSkipContent = true;
            }

            if (!shouldSkipContent)
            {
                if (bi.ItemType != "Compile" && bi.ItemType != "None")
                {
                    // but wait, the containing project may embed its content, so if so we need to check that
                    if (containingProject is CombinedEmbeddedContentProject &&
                        ((CombinedEmbeddedContentProject)containingProject).DefaultContentAction == bi.ItemType)
                    {
                        // Looks like it really is content
                        shouldSkipContent = false;
                    }
                    else
                    {
                        shouldSkipContent = true;
                    }
                }
            }

            if (!shouldSkipContent)
            {
                string extension = FileManager.GetExtension(bi.UnevaluatedInclude);

                if (ExtensionsToIgnore.Contains(extension))
                {
                    shouldSkipContent = true;
                }

                if (bi.ItemType == "Compile" && extension == "cs")
                {
                    shouldSkipContent = true;
                }
            }


            // Now that we have checked if we should process this, we want to check if we should exclude it
            if (!shouldSkipContent)
            {
                var rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(bi.UnevaluatedInclude);

                if (rfs != null && rfs.ProjectsToExcludeFrom.Contains(this.Name))
                {
                    shouldSkipContent = true;
                }
            }

            if (!shouldSkipContent)
            {
                string containingProjectContent   = FileManager.Standardize(containingProject.ContentDirectory).ToLowerInvariant();
                string standardUnevaluatedInclude = FileManager.Standardize(bi.UnevaluatedInclude).ToLowerInvariant();

                shouldSkipContent = standardUnevaluatedInclude.StartsWith(containingProjectContent) == false;
            }

            return(!shouldSkipContent);
        }
        private void AddContentFileItemsFrom(ProjectBase projectBase)
        {
            var contentItemsToSync =
                projectBase.ContentProject.EvaluatedItems.Where(item => IsContentFile(item, projectBase.ContentProject))
                .ToList();

            foreach (var bi in contentItemsToSync)
            {
                string absoluteFileName = projectBase.ContentProject.MakeAbsolute(bi.UnevaluatedInclude);

                bool forceToContent = false;
                if (projectBase.ContentCopiedToOutput)
                {
                    forceToContent = !bi.HasMetadata("CopyToOutputDirectory") &&
                                     CanBeContentType;
                }

                BuildItemMembershipType buildItemMembershipType = DefaultContentBuildType;
                if (forceToContent)
                {
                    buildItemMembershipType = BuildItemMembershipType.CompileOrContentPipeline;
                }
                else if (DefaultContentAction == "Content")
                {
                    buildItemMembershipType = BuildItemMembershipType.Content;
                }

                if (!ContentProject.IsFilePartOfProject(absoluteFileName, buildItemMembershipType, true))
                {
                    if (ContentProject.GetItem(absoluteFileName) != null)
                    {
                        ContentProject.RemoveItem(absoluteFileName);
                    }

                    ContentProject.AddContentBuildItem(absoluteFileName, SyncedProjectRelativeType.Linked, forceToContent);
                }


                var biOnThis = this.GetItem(absoluteFileName);
                // Let's process the path to make sure it's matching the latest standards - like
                // if we add additional restrictions at some point in Glue
                if (biOnThis != null)
                {
                    string includeBefore = biOnThis.UnevaluatedInclude;
                    string includeAfter  = ProcessInclude(biOnThis.UnevaluatedInclude);
                    if (includeBefore != includeAfter)
                    {
                        // simply changing the Include doesn't make a project
                        // dirty, and we only want to make it dirty if we really
                        // did change something so that we don't unnecessarily save
                        // projects.
                        biOnThis.UnevaluatedInclude = includeAfter;
                        this.IsDirty = true;
                    }

                    string linkBefore = biOnThis.GetLink();
                    if (!string.IsNullOrEmpty(linkBefore))
                    {
                        string linkAfter = ProcessLink(linkBefore);

                        // If the original project is linking a file outside of
                        // its own file structure, then the Link value assigned on
                        // this BuildItem will include "..\". This is an invalid link
                        // value, so we'll instead try to use the same link as in the original
                        // file:
                        {
                            var linkOnOriginalBuildItem = bi.GetLink();
                            if (string.IsNullOrEmpty(linkOnOriginalBuildItem) == false)
                            {
                                // first let's make the link relative to the main project's content folder
                                var relativeToProject = FileManager.MakeRelative(linkOnOriginalBuildItem, projectBase.ContentProject.ContentDirectory);

                                linkAfter = this.ContentDirectory + relativeToProject;
                                linkAfter = ProcessLink(linkAfter);
                            }
                        }


                        if (linkBefore != linkAfter)
                        {
                            // simply changing the Link doesn't make a project
                            // dirty, and we only want to make it dirty if we really
                            // did change something so that we don't unnecessarily save
                            // projects.
                            biOnThis.SetLink(linkAfter);
                            this.IsDirty = true;
                        }
                    }
                }
            }
        }
 public abstract void SyncTo(ProjectBase projectBase, bool performTranslation);
Beispiel #7
0
        public static CreateProjectResult CreateProject(string fileName)
        {
            //Project coreVisualStudioProject = new Project(fileName);
            Project             coreVisualStudioProject = null;
            CreateProjectResult result = new CreateProjectResult();

            var didErrorOccur = false;

            try
            {
                try
                {
                    coreVisualStudioProject = new Project(fileName, null, null, new ProjectCollection());
                }
                catch (Microsoft.Build.Exceptions.InvalidProjectFileException exception)
                {
                    // This is a bug I haven't been able to figure out, but have asked about here:
                    // https://stackoverflow.com/questions/46384075/why-does-microsoft-build-framework-dll-15-3-not-load-csproj-15-1-does
                    // So I'm going to hack a fix by checking if this has to do with 15.0 vs the other versions:

                    var message = exception.Message;
                    if (exception.Message.Contains("\"15.0\"") && exception.Message.Contains("\"14.0\""))
                    {
                        coreVisualStudioProject = new Project(fileName, null, "14.0", new ProjectCollection());
                    }
                    else
                    {
                        throw exception;
                    }
                }
            }
            catch (Microsoft.Build.Exceptions.InvalidProjectFileException exception)
            {
                didErrorOccur = true;
                var exceptionMessage = exception.Message;

                var    shouldThrowException = true;
                string locationToOpen       = null;

                bool   isMissingMonoGame = exceptionMessage.Contains("MonoGame.Content.Builder.targets\"");
                string message;
                if (isMissingMonoGame)
                {
                    message                       = $"Could not load the project {fileName}\nbecause MonoGame files are missing. Try installing MonoGame, then try opening the project in Glue again.\n\n";
                    locationToOpen                = "http://teamcity.monogame.net/repository/download/MonoGame_PackagingWindows/latest.lastSuccessful/MonoGameSetup.exe?guest=1";
                    shouldThrowException          = false;
                    result.ShouldTryToLoadProject = false;
                }
                else if (exceptionMessage.Contains("Novell.MonoDroid.CSharp.targets"))
                {
                    message = "This project references Novell.MonoDroid.CSharp.targets, " +
                              "which is an old file that used to be installed by Xamarin, but which " +
                              "is now replaced by a different .targets file. You can fix this by editing " +
                              "the .csproj file and changing the reference to the Xamarin version. You can " +
                              " also look at a new FlatRedBall Android project to see what this looks like.";
                    result.ShouldTryToLoadProject = false;
                }
                else if (exceptionMessage.Contains("Xamarin.Android.CSharp.targets"))
                {
                    message        = @"Error loading this Android project. Please verify that you have correctly installed the requirements to build Android projects. Opening:
https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/windows";
                    locationToOpen = "https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/windows";
                    result.ShouldTryToLoadProject = false;
                    shouldThrowException          = false;
                }

                else
                {
                    message = $"Could not load the project {fileName}\n" +
                              $"Usually this occurs if the Visual Studio XNA plugin is not installed\n\n";
                }

                if (shouldThrowException)
                {
                    throw new Exception(message, exception);
                }
                else
                {
                    Plugins.ExportedImplementations.GlueCommands.Self.DialogCommands.ShowMessageBox(message);

                    if (locationToOpen != null)
                    {
                        System.Diagnostics.Process.Start(locationToOpen);
                    }
                }
            }

            ProjectBase projectBase = null;

            if (didErrorOccur == false)
            {
                projectBase = CreatePlatformSpecificProject(coreVisualStudioProject, fileName);
            }

#if GLUE
            // It may be null if the project is of an unknown type.
            // We'll handle that problem outside of this function.
            if (projectBase != null)
            {
                projectBase.Saving += FlatRedBall.Glue.IO.FileWatchManager.IgnoreNextChangeOnFile;
                // Saving seems to cause 2 file changes, so we're going to ignore 2, what a hack!
                projectBase.Saving += FlatRedBall.Glue.IO.FileWatchManager.IgnoreNextChangeOnFile;
            }
#endif

            result.Project = projectBase;
            return(result);
        }
Beispiel #8
0
        private static ProjectBase TryGetProjectTypeFromDefineConstants(Project coreVisualStudioProject, out string message)
        {
            string preProcessorConstants = GetPreProcessorConstantsFromProject(coreVisualStudioProject);

            //string sasfd = ProjectManager.LibrariesPath;

            // Check for other platforms before checking for FRB_XNA because those projects
            // include FRB_XNA in them

            ProjectBase toReturn = null;

            message = null;

            var projectFilePath      = new FilePath(coreVisualStudioProject.ProjectFileLocation.File);
            var possibleStandardFile = new FilePath(projectFilePath.GetDirectoryContainingThis().GetDirectoryContainingThis() + "/GameStandard/GameStandard.csproj");

            if (possibleStandardFile.Exists())
            {
                var standardProject = new Project(possibleStandardFile.FullPath, null, null, new ProjectCollection());

                toReturn = new VisualStudioDotNetStandardProject(coreVisualStudioProject, standardProject);
            }
            else
            {
                List <PreprocessorAndFunc> loadCalls = new List <PreprocessorAndFunc>();

                loadCalls.Add(new PreprocessorAndFunc("ANDROID", () => new AndroidProject(coreVisualStudioProject)));
                loadCalls.Add(new PreprocessorAndFunc("IOS", () => new IosMonogameProject(coreVisualStudioProject)));
                loadCalls.Add(new PreprocessorAndFunc("UWP", () => new UwpProject(coreVisualStudioProject)));
                loadCalls.Add(new PreprocessorAndFunc("DESKTOP_GL", () => new DesktopGlProject(coreVisualStudioProject)));
                // Do XNA_4 last, since every
                // other project type has this
                // preprocessor type, so every project
                // type would return true here
                loadCalls.Add(new PreprocessorAndFunc("XNA4", () => new Xna4Project(coreVisualStudioProject)));
                // handled above, because it requires 2 projects to construct:
                //loadCalls.Add(new PreprocessorAndFunc("Standard", () => new VisualStudioDotNetStandardProject(coreVisualStudioProject)));


                foreach (var call in loadCalls)
                {
                    if (preProcessorConstants.Contains(call.Preprocessor))
                    {
                        toReturn = call.Func();
                        break;
                    }
                }
                message = null;
                if (toReturn == null)
                {
                    message = $"Could not determine project type from preprocessor directives." +
                              $"\nThe project beign loaded has the folowing preprocessor directives\"{preProcessorConstants}\"" +
                              $"\nThe following are preprocessor directives to determine project type:";

                    foreach (var preprocessor in loadCalls)
                    {
                        message += "\n" + preprocessor.Preprocessor;
                    }
                }
            }



            return(toReturn);
        }