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); } }
/// <summary> /// Build the Flutter module to generate the Android Archive (AAR) and/or the iOS framework /// that will be embedded into Xamarin applications. /// </summary> private static void BuildFlutterModule(NewProjectSettings settings, bool verbose = false) { try { if (settings.TargetAndroid) { FlutterTools.BuildAndroidArchive(settings.FlutterModulePath, FlutterModuleBuildConfig.Debug | FlutterModuleBuildConfig.Release, verbose); } if (settings.TargetIos && OperatingSystem.IsMacOS()) { FlutterTools.BuildIosFramework(settings.FlutterModulePath, FlutterModuleBuildConfig.Debug | FlutterModuleBuildConfig.Release, verbose); } } catch (Exception e) { throw new CommandLineException(CommandLineErrorCode.NewProject_BuildFlutterModuleFailed, e); } }
private static void SetNativeReferences(NewProjectSettings settings, DartProject project) { try { if (settings.TargetAndroid) { string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.ModuleInterop.Android", $"{settings.ProjectName}.ModuleInterop.Android.csproj"); SetNativeReference_AndroidBindings(csprojPath, project); } if (settings.TargetIos && OperatingSystem.IsMacOS()) { string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.PluginInterop.iOS", $"{settings.ProjectName}.PluginInterop.iOS.csproj"); SetNativeReference_iOSBindings(csprojPath, project); csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.iOS", $"{settings.ProjectName}.iOS.csproj"); SetNativeReference_iOSApp(csprojPath, project); } } catch (Exception e) { Log.Ex(e); throw new CommandLineException(CommandLineErrorCode.NewProject_SetNativeReferencesFailed, e); } }
/// <summary> /// Configures the post-build event of the .NET Standard class library. /// </summary> public static void ConfigurePostBuildEvent(NewProjectSettings settings, bool verbose = false) { try { string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.ServiceLibrary", $"{settings.ProjectName}.ServiceLibrary.csproj"); string executableWin; string executableMac; if (OperatingSystem.IsWindows()) { executableWin = Path.Combine(AppSettings.Default.AppPath, "flutnet.exe"); executableMac = $"{AppSettings.DefaultBinPath_macOS}/flutnet"; } else { executableWin = $"{AppSettings.DefaultBinPath_Windows}\\flutnet.exe"; executableMac = Path.Combine(AppSettings.Default.AppPath, "flutnet"); } ProjectRootElement prjElement = ProjectRootElement.Open(csprojPath); // Configures the post-build event(s) for Visual Studio for Mac List <string> commandArguments = new List <string> { executableMac.Quoted(), "pack", "-a", "${TargetFile}".Quoted(), "-n", settings.FlutterPackageName, "-o", (settings.CreateFlutterSubfolder ? $"${{SolutionDir}}/{settings.FlutterSubfolderName}" : "${SolutionDir}").Quoted(), "--force" }; foreach (ProjectPropertyGroupElement groupElement in prjElement.PropertyGroups) { if (groupElement.Condition.Contains("$(Configuration)") && groupElement.Condition.Contains("$(Platform)")) { ProjectPropertyElement propElement = groupElement.Properties.FirstOrDefault(p => p.Name == "CustomCommands"); propElement.Value = propElement.Value .Replace("<command></command>", $"<command>{string.Join(' ', commandArguments)}</command>"); } } // Configures the post-build event(s) for Visual Studio List <string> taskArguments = new List <string> { executableWin.Quoted(), "pack", "-a", "$(TargetPath)".Quoted(), "-n", settings.FlutterPackageName, "-o", (settings.CreateFlutterSubfolder ? $"$(SolutionDir)\\{settings.FlutterSubfolderName}" : "$(SolutionDir)").Quoted(), "--force" }; ProjectTargetElement targetElement = prjElement.Targets.FirstOrDefault(t => t.Name == "PostBuild"); ProjectTaskElement taskElement = targetElement.AddTask("Exec"); taskElement.SetParameter("Command", string.Join(' ', taskArguments)); prjElement.Save(); } catch (Exception e) { Log.Ex(e); throw new CommandLineException(CommandLineErrorCode.NewProject_CreateDotNetProjectsFailed, e); } }