I’ve been working with .NET core recently and I’d like to post some random observations on this subject for the future reference.
-
It is possible to create Nuget package upon build. This option is actually available also from the VS2017 Project properties GUI. Add this code to
csproj
.This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<propertygroup> <targetframework>netstandard2.0</targetframework> <generatepackageonbuild>true</generatepackageonbuild> <packageoutputpath>$(UserProfile)</packageoutputpath> <version>0.0.1</version> </propertygroup> -
It is possible to add local folder as Nuget feed. The folder can also be current user’s profile. This one is actually not Core specific.
Nuget.config
should look like this:This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<?xml version="1.0" encoding="utf-8"?> <configuration> <packagesources> <add key="CustomNugetSource" value="https://"></add> <add key="LocalPackages" value="%userprofile%"></add> </packagesources> <activepackagesource> <!-- this tells that all of them are active --> <add key="All" value="(Aggregate source)"></add> </activepackagesource> <packagesourcecredentials> <customnugetsource> <add key="Username" value="Reader"></add> <add key="ClearTextPassword" value=""></add> </customnugetsource> </packagesourcecredentials> <apikeys> <add key="key" value="value"></add> </apikeys> <solution> <add key="disableSourceControlIntegration" value="true"></add> </solution> </configuration> -
You can compile for multiple targets in
.NET Core
compatiblecsproj
. Please note the trailing s in the tag name. You can also conditionally include items incsproj
. Use the following snippets:This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<targetframeworks>netstandard2.0;net45;net40</targetframeworks> and:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<itemgroup Condition=" '$(TargetFramework)' == 'net45' "> </itemgroup> There is a reference documentation for the available targets: here.
-
The listening port in Kestrel can be configured in multiple ways. It can be read from environment variable or can be passed as command line argument. An asterisk is required to bind to physical interfaces. It is needed e.g. when trying to display the application from mobile phone when being served from development machine. The following are equivalent:
set ASPNETCORE_URLS=http://*:11399 --urls http://*:11399
-
The preferred way to pass hosting parameters to Kestrel is
launchSettings.json
file located inProperties
of the solution root. You can select a profile defined there when running:dotnet run --launch-profile "Dev"
dotnet run
is used to build and run from the directory wherecsproj
resides. It is not a good idea to run the app’s dll directly. Settings file can be missing frombin
folder and/or launch profile may not be present there.