Skip to content

Commit 3f582d6

Browse files
Merge pull request #457 from kojo12228/add-fsharp-support
Search for .csproj and .fsproj in init and add commands
2 parents 18c5a65 + 7489543 commit 3f582d6

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

ElectronNET.CLI/Commands/AddCommand.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ public Task<bool> ExecuteAsync()
7575
// ToDo: Not sure if this runs under linux/macos
7676
ProcessHelper.CmdExecute(@"npx tsc -p ../../", targetFilePath);
7777

78-
// search .csproj
79-
Console.WriteLine($"Search your .csproj to add configure CopyToPublishDirectory to 'Never'");
80-
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();
78+
// search .csproj or .fsproj (.csproj has higher precedence)
79+
Console.WriteLine($"Search your .csproj/.fsproj to add configure CopyToPublishDirectory to 'Never'");
80+
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
81+
.Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
82+
.FirstOrDefault();
8183

82-
Console.WriteLine($"Found your .csproj: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");
84+
var extension = Path.GetExtension(projectFile);
85+
Console.WriteLine($"Found your {extension}: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");
8386

84-
if (!EditCsProj(projectFile)) return false;
87+
if (!EditProjectFile(projectFile)) return false;
8588

8689
Console.WriteLine($"Everything done - happy electronizing with your custom npm packages!");
8790

@@ -90,7 +93,7 @@ public Task<bool> ExecuteAsync()
9093
}
9194

9295
// ToDo: Cleanup this copy/past code.
93-
private static bool EditCsProj(string projectFile)
96+
private static bool EditProjectFile(string projectFile)
9497
{
9598
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
9699
{
@@ -128,7 +131,7 @@ private static bool EditCsProj(string projectFile)
128131

129132
}
130133

131-
Console.WriteLine($"Publish setting added in csproj!");
134+
Console.WriteLine($"Publish setting added in csproj/fsproj!");
132135
return true;
133136
}
134137

ElectronNET.CLI/Commands/InitCommand.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,22 @@ public Task<bool> ExecuteAsync()
7070
// Deploy config file
7171
EmbeddedFileHelper.DeployEmbeddedFileToTargetFile(currentDirectory, DefaultConfigFileName, ConfigName);
7272

73-
// search .csproj
74-
Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
75-
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();
76-
77-
// update config file with the name of the csproj
78-
// ToDo: If the csproj name != application name, this will fail
73+
// search .csproj/.fsproj (.csproj has higher precedence)
74+
Console.WriteLine($"Search your .csproj/fsproj to add the needed {ConfigName}...");
75+
var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
76+
.Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
77+
.FirstOrDefault();
78+
79+
// update config file with the name of the csproj/fsproj
80+
// ToDo: If the csproj/fsproj name != application name, this will fail
7981
string text = File.ReadAllText(targetFilePath);
8082
text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile));
8183
File.WriteAllText(targetFilePath, text);
8284

83-
Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it.");
85+
var extension = Path.GetExtension(projectFile);
86+
Console.WriteLine($"Found your {extension}: {projectFile} - check for existing config or update it.");
8487

85-
if (!EditCsProj(projectFile)) return false;
88+
if (!EditProjectFile(projectFile)) return false;
8689

8790
// search launchSettings.json
8891
Console.WriteLine($"Search your .launchSettings to add our electron debug profile...");
@@ -158,7 +161,7 @@ private static void EditLaunchSettings(string currentDirectory)
158161
}
159162
}
160163

161-
private static bool EditCsProj(string projectFile)
164+
private static bool EditProjectFile(string projectFile)
162165
{
163166
using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
164167
{
@@ -174,11 +177,11 @@ private static bool EditCsProj(string projectFile)
174177

175178
if (xmlDocument.ToString().Contains($"Content Update=\"{ConfigName}\""))
176179
{
177-
Console.WriteLine($"{ConfigName} already in csproj.");
180+
Console.WriteLine($"{ConfigName} already in csproj/fsproj.");
178181
return false;
179182
}
180183

181-
Console.WriteLine($"{ConfigName} will be added to csproj.");
184+
Console.WriteLine($"{ConfigName} will be added to csproj/fsproj.");
182185

183186
string itemGroupXmlString = "<ItemGroup>" +
184187
"<Content Update=\"" + ConfigName + "\">" +
@@ -204,7 +207,7 @@ private static bool EditCsProj(string projectFile)
204207

205208
}
206209

207-
Console.WriteLine($"{ConfigName} added in csproj!");
210+
Console.WriteLine($"{ConfigName} added in csproj/fsproj!");
208211
return true;
209212
}
210213
}

0 commit comments

Comments
 (0)