Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 06 10:43
    bitbonk opened #52
  • Apr 09 15:36
    yehudamakarov edited #51
  • Apr 09 15:35
    yehudamakarov opened #51
  • Apr 07 13:26
    lvermeulen commented #50
  • Apr 07 13:26
    lvermeulen commented #50
  • Apr 07 13:26
    lvermeulen commented #50
  • Apr 07 13:25
    lvermeulen commented #50
  • Apr 07 13:24
    lvermeulen commented #50
  • Apr 07 13:24
    lvermeulen commented #50
  • Apr 07 12:23
    lvermeulen edited #50
  • Apr 07 12:22
    lvermeulen opened #50
  • Mar 17 14:59
    ejsmith commented #49
  • Mar 17 14:10

    jeremydmiller on master

    added configuration preview, bu… (compare)

  • Mar 17 13:56

    jeremydmiller on master

    Add ability to modify the HostB… (compare)

  • Mar 17 13:56
    jeremydmiller closed #49
  • Feb 24 16:34
    ejsmith review_requested #49
  • Feb 23 15:44
    ejsmith opened #49
  • Feb 22 16:23

    jeremydmiller on master

    Removed dump usages, bumps to 3… (compare)

  • Feb 22 15:09

    jeremydmiller on master

    streamlined run command, bumps … (compare)

  • Feb 22 15:04

    jeremydmiller on master

    streamlined run command, bumps … (compare)

Jeremy D. Miller
@jeremydmiller
@hmvs If it’s mandatory, just use an argument. There’s nothing stopping you from validating the command line input in the commands for that matter and throwing an explanatory exception if flag values are missing
Mo Zaatar ﮼محمدزعتر﮼
@MZaatar_twitter
Hello, anyone has any idea how could I pass a default flag (without adding -- in front of it). Example:
My current command is myExe --option1 "option1" --option2 "option2"
What I want to achieve is be able to run something like
myExe "option1" --option2 "option2"
myExe --option1 "option1" --option2 "option2"
Andy Davies
@Pondidum

You can achive something like what you are after...but it's not entirely pleasant. It involves using an argument and a flag, and specifying usages so that you either can use "argument + flag" or "flag + flag":

    public class TestInput
    {
        public string One { get; set; }
        public string OneFlag { get; set; }
        public string TwoFlag { get; set; }
    }

    public class TestCommand : OaktonCommand<TestInput>
    {
        public TestCommand()
        {
            Usage("default flag").Arguments(x => x.One).ValidFlags(x => x.TwoFlag);
            Usage("do it yourself flag").ValidFlags(x => x.OneFlag, x => x.TwoFlag);
        }

        public override bool Execute(TestInput input)
        {
            Console.WriteLine($"1: {input.One ?? input.OneFlag}");
            Console.WriteLine($"2: {input.TwoFlag}");

            return true;
        }
    }

Example usage:

# working usages:
dotnet OaktonTesting.dll test --one wat --two is
dotnet OaktonTesting.dll test wat --two is

# throws an error, as this is not a valid usage:
dotnet OaktonTesting.dll test omg --one wat --two is
Mo Zaatar ﮼محمدزعتر﮼
@MZaatar_twitter
Hey @Pondidum thanks for your reply. That was my guess but I thought that there is an easier one
Will implement it anyway as I want it :)
Mohamed Bareche
@neoexa
This message was deleted

Hello i have an opts file where i defined some flags, when running my command the program appends the flags this way
mytool -u MyUserName -p ~~HeMan2345 somecommand
instead of

mytool somecommand -u MyUserName -p ~~HeMan2345
which gives me an error : -u is not a command

Any tips ?! Thanks

Jeremy D. Miller
@jeremydmiller
It’s a bug if anything
Mohamed Bareche
@neoexa
@jeremydmiller Ok, i'll look more into it (i'll keep you updated)
Yehuda Makarov
@yehudamakarov

Hey guys. great library! thank you!

Log.Information("Starting web host");
return CreateHostBuilder(args).RunOaktonCommands(args);
//CreateHostBuilder(args).Build().Run();
//return Task.FromResult(0);

anyone know why I lose my logs when i use the oakton commands instead? all I get is the one log before serilog is supposed to take over

bitbonk
@bitbonk
Hi, I have this super simple .NET Core static file server. Now I would like to feed in the settings for webroot and the listen port from from commandline args using Oakton. Oakton command line args should override what may have already been set by appsettings.json or appsettings.Development.json. Can this be done somehow?
public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(
                webBuilder =>
                {
                    // There are two problems with the following two lines.
                    // 1. Where do I get configuration instance from?
                    // 2. How do I merge them with Okaton commandline args?
                    webBuilder.UseWebRoot(configuration.GetValue<string>("MySection:webroot"));
                    webBuilder.UseUrls($"http://localhost:{configuration.GetValue<int>("MySection:port")}");

                    webBuilder.UseStartup<Startup>();
                });
}

public class Startup
{
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseDefaultFiles();
        app.UseStaticFiles();
    }
}
David Smith
@flipdoubt

Two quick questions:

  1. What does Oakton.AspNetCore provide that the Oakton package does not?
  2. Is there a simple way to replace the internal IConfiguration Preview?

Thanks for this library. It rocks.

Jeremy D. Miller
@jeremydmiller
Oakton.AspNetCore is obsolete and got completely folded into Oakton for the last big release
2.) I take pull requests ;)
And thanks!
David Smith
@flipdoubt
@jeremydmiller even if the pull request simply changes the access modifier from internal to public? Just curious as to why you went with internal.
Jeremy D. Miller
@jeremydmiller
I can’t say I ever thought about the configuration preview being swappable, so there was no reason to make it public
David Smith
@flipdoubt
When running my code on a machine without Visual Studio, I get an error with the following stack trace. I searched the docs but didn't find anything regarding "Microsoft.CodeAnalysis". How can I fix this issue?
[2021-05-03 16:05:42Z] [FTL] [<s:>] WebApp failed to start.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'Microsoft.CodeAnalysis, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at System.Reflection.CustomAttribute.IsDefined(RuntimeAssembly assembly, RuntimeType caType)
   at System.Reflection.RuntimeAssembly.IsDefined(Type attributeType, Boolean inherit)
   at System.Attribute.IsDefined(Assembly element, Type attributeType, Boolean inherit)
   at System.Reflection.CustomAttributeExtensions.IsDefined(Assembly element, Type attributeType)
   at Baseline.Reflection.ReflectionExtensions.HasAttribute[T](Assembly provider)
   at Oakton.CommandFactory.<>c.<RegisterCommandsFromExtensionAssemblies>b__30_0(Assembly a)
Jeremy D. Miller
@jeremydmiller
Can you try cleaning off your code first, then trying it from scratch? That just smells like dotnet restore not running cleanly from trash left behind
David Smith
@flipdoubt
This is a staging machine, so it should be cleaner than my local machine where it works without error. One thing I haven't considered, however, is that it is a Production build instead of Debug, which I never really tested locally. Are there any considerations when running in production? dotnet run ... doesn't even work without the project file.
David Smith
@flipdoubt
Am I being silly in that this should never be in a release build?
Jeremy D. Miller
@jeremydmiller
I don’t know about that, but this just feels like a run of the mill Nuget dependency issue. Could be something has an incompatible reference to that Nuget, and it is a common diamond dependency.
We could relax the dependency in Baseline to let it float. That could easily be the culprit
David Smith
@flipdoubt
All I'm trying to do is test it with the output from dotnet publish ... and I can't even get the resulting binaries to recognize any of the Oakton commands. I can't use dotnet run ... here because there is no project file. How can I execute commands in a release build?
Jeremy D. Miller
@jeremydmiller
It publishes to an exe, right?
the results of dotnet publish?
Or if it writes to a dll, you can run that through dotnet run [assembly file name]. It’s been awhile since I’ve done that, so it might be a flag of some sort
David Smith
@flipdoubt

In dotnet core, dotnet run app.exe or any file produces a response like the following:

Couldn't find a project to run. Ensure a project exists in C:\code\publish\App, or pass the path to the project using --project.

From the dotnet-run docs:

The dotnet run command is used in the context of projects, not built assemblies. If you're trying to run a framework-dependent application DLL instead, you must use dotnet without a command.

Are people only using Oakton on source projects or on release builds as well?

Jeremy D. Miller
@jeremydmiller
If you have an exe, you should be able to just go “myapp [args]"
And folks are using Oakton to run .Net Core projects in production, yes. I’ve done that as well
David Smith
@flipdoubt
Excellent. So how do you invoke the describe command on a dotnet core executable compiled for release? For me, app.exe --describe or app.exe --help return without any console output.
Jeremy D. Miller
@jeremydmiller
app.exe describe
app.exe help should give you the help output
You wouldn’t need the double dash if you’re running from the executable instead of dotnet run
David Smith
@flipdoubt
Ah, ok. When I run app.exe help on my dev machine, my app logs the same FileNotFoundException referencing "Microsoft.CodeAnalysis". Now that I can reproduce that locally, I will go through the cleaning exercise.
Jeremy D. Miller
@jeremydmiller
So we still have the Nuget problem. You might see what version of that nuget gets published by dotnet publish
David Smith
@flipdoubt

Same result.

Which package are you referring to with "you might see what version of that nuget gets published by dotnet publish"? There is no Microsoft.CodeAnalysis.dll in the publish output.

Jeremy D. Miller
@jeremydmiller
Yeah, and that’s your problem
So when it says FileNotFoundException, it’s unable to load the assembly referenced. You might try making a direct dependency to that nuget package w/ that version
David Smith
@flipdoubt
Got it.
Thanks.
Jeremy D. Miller
@jeremydmiller
Sorry this is being frustrating. We’ve all been there.
bitbonk
@bitbonk
This is super cool, this should be part of Oakton: https://andrewlock.net/viewing-overriden-configuration-values-in-aspnetcore/
Jeremy D. Miller
@jeremydmiller
@bitbonk It is in 4.1 just by dumping out the built in ConfigurationRoot diagnostics, but not as pretty as what he did. Sounds like a good PR:)
bitbonk
@bitbonk
especially the overwritten values view, this is a live saver
Jeremy D. Miller
@jeremydmiller
Yup. I added it specifically for a project at work for exactly that reason.
bitbonk
@bitbonk
I'll see if I can get a PR ready, just might need to ask if I may steal the code from that post
Jeremy D. Miller
@jeremydmiller
I don’t think he’d mind, and it should be a quick win. should
bitbonk
@bitbonk
@jeremydmiller So here we go: JasperFx/oakton#52
David Smith
@flipdoubt
After changing the standard CreateHostBuilder(args).Build().Run() to CreateHostBuilder(args).RunOaktonCommands(args), some of the our middleware get loggers without log sinks configured. All I have to do is change to code back to fix it, so Build().Run(args) does something RunOaktonCommands(args) does not do. Any clue what that might be and whether there is a work around? It's as if Oakton doesn't call IHostBuilder.Build, but it is hard to tell.