Skip to content

Commit ad3dd18

Browse files
committed
Added the "CustomPathToDLLs" option.
Searches for any DLL in the specified directory. Previously, it was hardcoded to "./bin/". Default: "./bin/"
1 parent b5d7fca commit ad3dd18

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

CSharpToJavaScript/CSTOJS.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static MetadataReference[] GetReferences(CSTOJSOptions options)
129129

130130
string? assemblyPath = Path.GetDirectoryName(assembly?.Location);
131131
string? objectAssemblyPath = Path.GetDirectoryName(typeof(object).Assembly.Location);
132-
string? binPath = Directory.Exists("./bin/") ? "./bin/" : null;
132+
string? customPath = Directory.Exists(options.CustomPathToDLLs) ? options.CustomPathToDLLs : null;
133133

134134
if (assemblyNames.Length > 0)
135135
{
@@ -176,9 +176,9 @@ private static MetadataReference[] GetReferences(CSTOJSOptions options)
176176
if (File.Exists(Path.Combine(objectAssemblyPath, "System.Console.dll")))
177177
assemblyMetadata.Add(MetadataReference.CreateFromFile(Path.Combine(objectAssemblyPath, "System.Console.dll")));
178178
}
179-
if (binPath != null)
179+
if (customPath != null)
180180
{
181-
string[] files = Directory.GetFiles(binPath, "*.dll", SearchOption.AllDirectories);
181+
string[] files = Directory.GetFiles(customPath, "*.dll", SearchOption.AllDirectories);
182182
for (int j = 0; j < files.Length; j++)
183183
{
184184
assemblyMetadata.Add(MetadataReference.CreateFromFile(files[j]));
@@ -188,14 +188,16 @@ private static MetadataReference[] GetReferences(CSTOJSOptions options)
188188
{
189189
Log.InfoLine($"+++");
190190

191-
Log.InfoLine($"assemblyPath: {assemblyPath}");
192-
Log.InfoLine($"objectAssemblyPath: {objectAssemblyPath}");
193-
Log.InfoLine($"binPath: {binPath}");
191+
Log.InfoLine($"assemblyPath: '{assemblyPath}'");
192+
Log.InfoLine($"objectAssemblyPath: '{objectAssemblyPath}'");
193+
Log.InfoLine($"binPath: '{customPath}'");
194194

195195
foreach (MetadataReference metadata in assemblyMetadata)
196196
{
197197
Log.WriteLine(metadata.Display ?? "null display string");
198198
}
199+
200+
Log.InfoLine($"assemblyMetadata count: '{assemblyMetadata.Count}'");
199201
Log.InfoLine($"---");
200202
}
201203

@@ -214,6 +216,7 @@ private static MetadataReference[] GetReferences(CSTOJSOptions options)
214216
Log.WriteLine(references[j].Display ?? "null display string");
215217

216218
}
219+
Log.InfoLine($"references length: '{references.Length}'");
217220
Log.InfoLine($"+++");
218221
}
219222

CSharpToJavaScript/CSTOJSOptions.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,29 @@ public class CSTOJSOptions
137137
/// </value>
138138
public Dictionary<string, string> CustomCSNamesToJS { get; set; } = new();
139139

140+
/// <summary>
141+
/// Custom directory path to the DLLs.
142+
/// </summary>
143+
/// <remarks>
144+
/// <para>
145+
/// Searches for any DLL in the specified directory and then imports references into compilation.
146+
/// </para>
147+
/// <blockquote class="NOTE"><h5>NOTE</h5>
148+
/// <para>
149+
/// cstojs_options.xml: &lt;Option CustomPathToDLLs=&quot;./bin&quot; /&gt;
150+
/// </para>
151+
/// </blockquote>
152+
/// <blockquote class="IMPORTANT"><h5>IMPORTANT</h5>
153+
/// <para>
154+
/// The option needs to be specified in the first file or globally if using CSTOJS_CLI.
155+
/// </para>
156+
/// </blockquote>
157+
/// </remarks>
158+
/// <value>
159+
/// Default: <c>./bin/</c>
160+
/// </value>
161+
public string CustomPathToDLLs { get; set; } = "./bin/";
162+
140163
/// <summary>
141164
/// Add a <see cref="StringBuilder" /> to the front of a javascript file.
142165
/// </summary>

0 commit comments

Comments
 (0)