Пример #1
0
        private static Version GetVersionForTests(ISolution solution)
        {
            // The project file data provider/cache doesn't work in tests, because there is no .csproj file we can parse.
            // Instead, pull the version directly from the project defines in the project model. We can't rely on this
            // as our main strategy because Unity doesn't write defines for Release configuration (another reason we for
            // us to hide the project configuration selector)
            var unityVersion = new Version(0, 0);

            foreach (var project in GetTopLevelProjectWithReadLock(solution))
            {
                foreach (var configuration in project.ProjectProperties.GetActiveConfigurations <IManagedProjectConfiguration>())
                {
                    // Get the constants. The tests can't set this up correctly, so they
                    // add the Unity version as a property
                    var defineConstants = configuration.DefineConstants;
                    if (string.IsNullOrEmpty(defineConstants))
                    {
                        configuration.PropertiesCollection.TryGetValue("DefineConstants", out defineConstants);
                    }

                    unityVersion = UnityProjectFileCacheProvider.GetVersionFromDefines(defineConstants ?? string.Empty,
                                                                                       unityVersion);
                }
            }

            return(unityVersion);
        }
Пример #2
0
        private Version GetActualVersion(ISolution solution)
        {
            foreach (var project in solution.GetTopLevelProjects())
            {
                if (project.IsUnityProject())
                {
                    var version = myUnityProjectFileCache.GetUnityVersion(project);
                    if (version != null)
                    {
                        return(version);
                    }
                }
            }

            // Tests don't create a .csproj we can parse, so pull the version out
            // of the project defines directly (we can't do this normally because
            // Unity doesn't write defines for Release configuration, so we can't
            // rely on this)
            Version unityVersion = null;

            foreach (var project in solution.GetTopLevelProjects())
            {
                foreach (var configuration in project.ProjectProperties.GetActiveConfigurations <IManagedProjectConfiguration>())
                {
                    unityVersion = UnityProjectFileCacheProvider.GetVersionFromDefines(configuration.DefineConstants ?? string.Empty,
                                                                                       unityVersion);
                }
            }

            // If all else fails, default to 5.4. The majority of the tests will
            // rely on this being set.
            return(unityVersion ?? new Version(5, 4));
        }
Пример #3
0
        private Version GetActualVersion(ISolution solution)
        {
            foreach (var project in solution.GetTopLevelProjects())
            {
                if (project.IsUnityProject())
                {
                    var version = myUnityProjectFileCache.GetUnityVersion(project);
                    if (version != null)
                    {
                        return(version);
                    }
                }
            }

            // Tests don't create a .csproj we can parse, so pull the version out
            // of the project defines directly (we can't do this normally because
            // Unity doesn't write defines for Release configuration, so we can't
            // rely on this)
            Version unityVersion = null;

            foreach (var project in solution.GetTopLevelProjects())
            {
                foreach (var configuration in project.ProjectProperties.GetActiveConfigurations <IManagedProjectConfiguration>())
                {
                    // Get the constants. The tests can't set this up correctly, so they
                    // add the Unity version as a property
                    var defineConstants = configuration.DefineConstants;
                    if (string.IsNullOrEmpty(defineConstants))
                    {
                        configuration.PropertiesCollection.TryGetValue("DefineConstants", out defineConstants);
                    }

                    unityVersion = UnityProjectFileCacheProvider.GetVersionFromDefines(defineConstants ?? string.Empty,
                                                                                       unityVersion);
                }
            }

            // If all else fails, default to 5.4. No reason for that version, other
            // than it was the first supported version :)
            return(unityVersion ?? new Version(5, 4));
        }