-
Notifications
You must be signed in to change notification settings - Fork 177
Feature/create and execute dll #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/create and execute dll #315
Conversation
release config now emits no debug info copying over obj info @ publish time for nuget package info
adding publish dll tests
src/Dotnet.Script/Program.cs
Outdated
@@ -133,17 +133,20 @@ private static int Wain(string[] args) | |||
c.Description = "Creates an executable from a script"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please update the description here (or DLL
)
src/Dotnet.Script/Program.cs
Outdated
var publishDebugMode = c.Option(DebugFlagShort + " | " + DebugFlagLong, "Enables debug output.", CommandOptionType.NoValue); | ||
c.OnExecute(() => | ||
{ | ||
var x = debugMode.HasValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's x
? 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate that visual studio didn't give a warning for this type of unused variable...
src/Dotnet.Script/Program.cs
Outdated
@@ -133,17 +133,20 @@ private static int Wain(string[] args) | |||
c.Description = "Creates an executable from a script"; | |||
var fileNameArgument = c.Argument("filename", "The script file name"); | |||
var publishDirectoryOption = c.Option("-o |--output", "Directory where the published executable should be placed. Defaults to a 'publish' folder in the current directory.", CommandOptionType.SingleValue); | |||
var dllOption = c.Option("--dll", "Publish to a .dll instead of a .exe", CommandOptionType.NoValue); | |||
var commandConfig = c.Option("-c | --configuration <configuration>", "Configuration to use for running the script [Release/Debug] Default is \"Debug\"", CommandOptionType.SingleValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need an extra option instead of the already existing top-level var configuration = app.Option("-c | --configuration <configuration>"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you mentioned this. I tested trying to access "app" level "options" when executing a sub "command", and those options were not coming through and required me to create new variables in order to access them at the "command" level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am barely able to handle this argument parsing library 😀 so I now suspect this is happening because the publish
is a command so it creates a new context and all the arguments are parsed within this context, not in the global one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that has been the assumption I went with as well.
Thanks a lot, great work! 🍻
I think this has certain problems and we will have to change it - like you mentioned, if the packages are gone, or if you move to a different machine where they are not there, or if you move to a different OS (then they might be there, just in different place). That said, I think this is a reasonable 1st version though, this is more or less how it worked in scriptcs in the past too, and we can describe it as known limitation for now, and improve later. Also, the way I'd view compile to
This is not a bad idea. I want debug info to always be there for standard scripting scenarios, but once we deal with exe/dll I think it makes sense to respect the configuration.
why not generate the name of the DLL from the entry CSX file? |
So for the generated DLL name, since the name of the script is usually less descriptive than the folder, I went with the folder. Using |
I think we should use the script name. Perhaps we can have another switch, something like |
{ | ||
try | ||
{ | ||
var emitResult = _scriptEmitter.Emit<int>(context, AssemblyName); | ||
var emitResult = _scriptEmitter.Emit<int>(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the PdbStream
property from the emitResult?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I already removed it since the debug information is embedded
@@ -16,30 +16,26 @@ public ScriptEmitter(ScriptConsole scriptConsole, ScriptCompiler scriptCompiler) | |||
_scriptCompiler = scriptCompiler; | |||
} | |||
|
|||
public virtual ScriptEmitResult Emit<TReturn>(ScriptContext context, string assemblyName = null) | |||
public virtual ScriptEmitResult Emit<TReturn>(ScriptContext context) | |||
{ | |||
try | |||
{ | |||
var compilationContext = _scriptCompiler.CreateCompilationContext<TReturn, CommandLineScriptGlobals>(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that on other code paths (i.e. script execution) we support using custom host types. This is not very important but in the future the publish code should probably be extended with that
misc review changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature continues with my previous publish to .exe PR #312 as well as Filip's POC e677cd6 to create and execute a .dll .
I made improvements to the way we were emitting the streams in ScriptEmitter:
-c release
is supplied, then no debug information will be created..dll generation considerations:
--dll
flag is passed to thepublish
command, the script is outputted to a .dll in a publish directory in the working directory (configurable), along w/ any .dll's the script referenced via#r
. Getting Nuget packages working was trickier. I elected to not move over the assembly files to the publish directory during a publish, instead moving 2 files from the "obj" folder, "project.assets.json", and "script.csproj.nuget.g.props" to determine the necessary nuget information when the generated .dll is executed. 1 caveat to doing this, is no nuget restore takes place at execution time. I figured this would be ok after I tested thedotnet test.dll
command and saw that it does not restore nuget packages either. This does mean though that if you do a publish to dll, delete your nuget packages (or execute from a machine missing the packages), then try to execute the dll, you will get a missing reference error.exec
command. This command calls the ScriptRunner, creates the dependency map from the obj information, runs the main script<Factory>
method, and then resolves missing nuget references.misc:
Dotnet.Script.Desktop.Tests
testsLooking forward to your feedback. Thanks