示例#1
0
        private static void UpdatePackageReferences(NewProjectSettings settings)
        {
            try
            {
                string productVersion = Assembly.GetEntryAssembly().GetProductVersion();
                string flutterVersion = settings.FlutterVersion;
                if (string.IsNullOrEmpty(flutterVersion))
                {
                    flutterVersion = FlutterTools.GetVersion().Version;
                }

                SdkVersion        sdk = AppSettings.Default.SdkTable.Versions.First(v => v.Version == productVersion);
                SdkFlutterVersion fv  = sdk.Compatibility.FirstOrDefault(f => VersionUtils.Compare(f.Version, flutterVersion) == 0);
                if (fv == null)
                {
                    // We're using a version of Flutter that is not officially supported by Flutnet (no binding libraries exist).
                    // Let's try and see if we can find a prior version that's fully compatible.
                    // If we can't find anything, simply return and keep the template configuration as is.
                    sdk.Compatibility.Sort(new SdkFlutterVersionComparer());
                    fv = sdk.Compatibility.LastOrDefault(f => VersionUtils.Compare(f.Version, flutterVersion) < 0);
                    if (fv == null)
                    {
                        return;
                    }
                }

                if (settings.TargetAndroid)
                {
                    string interopVersion = !string.IsNullOrEmpty(fv.AndroidInteropVersion)
                        ? fv.AndroidInteropVersion
                        : fv.Version;

                    string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.Android", $"{settings.ProjectName}.Android.csproj");
                    UpdatePackageReferences_AndroidProject(csprojPath, interopVersion);
                    csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.ModuleInterop.Android", $"{settings.ProjectName}.ModuleInterop.Android.csproj");
                    UpdatePackageReferences_AndroidProject(csprojPath, interopVersion);
                }

                if (settings.TargetIos && OperatingSystem.IsMacOS())
                {
                    string interopVersion = !string.IsNullOrEmpty(fv.IosInteropVersion)
                        ? fv.IosInteropVersion
                        : fv.Version;

                    string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.iOS", $"{settings.ProjectName}.iOS.csproj");
                    UpdatePackageReferences_iOSProject(csprojPath, interopVersion);
                    csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.PluginInterop.iOS", $"{settings.ProjectName}.PluginInterop.iOS.csproj");
                    UpdatePackageReferences_iOSProject(csprojPath, interopVersion);
                }
            }
            catch (Exception e)
            {
                throw new CommandLineException(CommandLineErrorCode.NewProject_SetNativeReferencesFailed, e);
            }
        }
示例#2
0
        public static CompatibilityResult CheckCompatibility(bool verbose = false)
        {
            try
            {
                string         productVersion = Assembly.GetEntryAssembly().GetProductVersion();
                FlutterVersion flutterVersion = FlutterTools.GetVersion(verbose);

                SdkVersion sdk = AppSettings.Default.SdkTable.Versions.First(v => v.Version == productVersion);
                sdk.Compatibility.Sort(new SdkFlutterVersionComparer());

                bool supported           = false; // Indicates whether this SDK explicitly supports the installed Flutter version
                SdkFlutterVersion prev   = null;  // The last supported Flutter version that precedes the installed one (can be NULL)
                SdkFlutterVersion next   = null;  // The first supported Flutter version that follows the installed one (can be NULL)
                SdkFlutterVersion latest = null;  // The latest supported Flutter version

                for (int i = 0; i < sdk.Compatibility.Count; i++)
                {
                    SdkFlutterVersion fv = sdk.Compatibility[i];
                    int compare          = VersionUtils.Compare(fv.Version, flutterVersion.Version);

                    if (compare == 0)
                    {
                        supported = true;
                        break;
                    }

                    if (compare < 0)
                    {
                        prev = fv;
                    }
                    else if (next == null)
                    {
                        next = fv;
                    }

                    if (i == sdk.Compatibility.Count - 1)
                    {
                        latest = fv;
                    }
                }

                FlutterCompatibility compatibility;
                if (supported)
                {
                    compatibility = FlutterCompatibility.Supported;
                }
                else if (prev != null)
                {
                    compatibility = FlutterCompatibility.SupportNotGuaranteed;
                }
                else
                {
                    compatibility = FlutterCompatibility.NotSupported;
                }

                CompatibilityResult result = new CompatibilityResult
                {
                    Compatibility          = compatibility,
                    InstalledVersion       = flutterVersion,
                    NextSupportedVersion   = next?.Version,
                    LatestSupportedVersion = latest?.Version
                };

                return(result);
            }
            catch (Exception ex)
            {
                Log.Ex(ex);
                Console.WriteLine(ex);
                throw;
            }
        }