diff --git a/ElectronNET.CLI/Commands/AddCommand.cs b/ElectronNET.CLI/Commands/AddCommand.cs index 8168d6dc..cbfb0dd6 100644 --- a/ElectronNET.CLI/Commands/AddCommand.cs +++ b/ElectronNET.CLI/Commands/AddCommand.cs @@ -75,13 +75,16 @@ public Task ExecuteAsync() // ToDo: Not sure if this runs under linux/macos ProcessHelper.CmdExecute(@"npx tsc -p ../../", targetFilePath); - // search .csproj - Console.WriteLine($"Search your .csproj to add configure CopyToPublishDirectory to 'Never'"); - var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault(); + // search .csproj or .fsproj (.csproj has higher precedence) + Console.WriteLine($"Search your .csproj/.fsproj to add configure CopyToPublishDirectory to 'Never'"); + var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly) + .Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly)) + .FirstOrDefault(); - Console.WriteLine($"Found your .csproj: {projectFile} - check for existing CopyToPublishDirectory setting or update it."); + var extension = Path.GetExtension(projectFile); + Console.WriteLine($"Found your {extension}: {projectFile} - check for existing CopyToPublishDirectory setting or update it."); - if (!EditCsProj(projectFile)) return false; + if (!EditProjectFile(projectFile)) return false; Console.WriteLine($"Everything done - happy electronizing with your custom npm packages!"); @@ -90,7 +93,7 @@ public Task ExecuteAsync() } // ToDo: Cleanup this copy/past code. - private static bool EditCsProj(string projectFile) + private static bool EditProjectFile(string projectFile) { using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { @@ -128,7 +131,7 @@ private static bool EditCsProj(string projectFile) } - Console.WriteLine($"Publish setting added in csproj!"); + Console.WriteLine($"Publish setting added in csproj/fsproj!"); return true; } diff --git a/ElectronNET.CLI/Commands/InitCommand.cs b/ElectronNET.CLI/Commands/InitCommand.cs index b0b96b53..c2539200 100644 --- a/ElectronNET.CLI/Commands/InitCommand.cs +++ b/ElectronNET.CLI/Commands/InitCommand.cs @@ -70,19 +70,22 @@ public Task ExecuteAsync() // Deploy config file EmbeddedFileHelper.DeployEmbeddedFileToTargetFile(currentDirectory, DefaultConfigFileName, ConfigName); - // search .csproj - Console.WriteLine($"Search your .csproj to add the needed {ConfigName}..."); - var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault(); - - // update config file with the name of the csproj - // ToDo: If the csproj name != application name, this will fail + // search .csproj/.fsproj (.csproj has higher precedence) + Console.WriteLine($"Search your .csproj/fsproj to add the needed {ConfigName}..."); + var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly) + .Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly)) + .FirstOrDefault(); + + // update config file with the name of the csproj/fsproj + // ToDo: If the csproj/fsproj name != application name, this will fail string text = File.ReadAllText(targetFilePath); text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile)); File.WriteAllText(targetFilePath, text); - Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it."); + var extension = Path.GetExtension(projectFile); + Console.WriteLine($"Found your {extension}: {projectFile} - check for existing config or update it."); - if (!EditCsProj(projectFile)) return false; + if (!EditProjectFile(projectFile)) return false; // search launchSettings.json Console.WriteLine($"Search your .launchSettings to add our electron debug profile..."); @@ -158,7 +161,7 @@ private static void EditLaunchSettings(string currentDirectory) } } - private static bool EditCsProj(string projectFile) + private static bool EditProjectFile(string projectFile) { using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { @@ -174,11 +177,11 @@ private static bool EditCsProj(string projectFile) if (xmlDocument.ToString().Contains($"Content Update=\"{ConfigName}\"")) { - Console.WriteLine($"{ConfigName} already in csproj."); + Console.WriteLine($"{ConfigName} already in csproj/fsproj."); return false; } - Console.WriteLine($"{ConfigName} will be added to csproj."); + Console.WriteLine($"{ConfigName} will be added to csproj/fsproj."); string itemGroupXmlString = "" + "" + @@ -204,7 +207,7 @@ private static bool EditCsProj(string projectFile) } - Console.WriteLine($"{ConfigName} added in csproj!"); + Console.WriteLine($"{ConfigName} added in csproj/fsproj!"); return true; } }