asp.net core launch profile and launch settings

ASP.NET Core –launch-profile and launchSettings.json

How to start application in ASP.NET Core from command line?

dotnet run

How to start application in ASP.NET Core in development mode?

set ASPNETCORE_ENVIRONMENT=Development
dotnet run

How to make it one command? Use launch profile, available in dotnet run command. But to make it work, there needs to be launchSettings.json file with profile definition, i.e. what needs to be done for application to run.

Definition I am using, inspired by web, is this:

{
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
        "applicationUrl": "http://localhost:5000/",
        "sslPort": 0
        }
    },
    "profiles": {
        "Dev": {
            "commandName": "Project",
            "launchBrowser": true,
            "launchUrl": "http://localhost:5000",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        }
    }
}

And to launch it in Dev mode all I have to do is:

dotnet run --launch-profile 'Dev'

And… it fails, saying it cannot find this profile. That is because what I did is place the file next to .csproj file. Seemed obvious. Well, it should not. Where this file needs to be is in Properties directory (\Properties\launchSettings.json). With this layout – it works perfectly fine. fine.

Advertisements

TIL jQuery extend function

Today I learned about jQuery extend function. It is quite simple to use and as useful as it is simple!

What it does? Simply merges one object into another, adding properties from other objects to our target. For example:

	var targetObject = {
		propertyA: "string1",
		propertyB: 12.3
	};

	var mergeObject = {
		propertyA: "overrideString",
		propertyC: new Date()
	}

	$.extend(targetObject, mergeObject);
	console.log(targetObject);

What we get in result is:

	object { propertyA: "overrideString", propertyB: 12.3, propertyC: Fri Feb 26 2016 18:03:47 GMT+0100 }

So merged object, with last win rule – the same property name will overwrite previous values in source objects. Or in fact in previous merge objects since you can pass multiple merge objects there.

What it is used for? Well, jQuery itself uses it to extend jQuery functionality. Wrote some jQuery plugin? you can $.extend(myPluginObject) and it will merge your object into jQuery (if there is only one param, jQuery is assumed as target). Why I find it useful? When initializing javascript structure, we often provide it with init data, however we want some of it to be taken from default if user did not provide overrides. That is easily done now:

	var actualConfig = $.extend({}, defaults, initData);

It will return new object, copying first values from our defaults and then overriding them with whatever user did provice in initData. Neat!