Docker error: CTC1014 Docker command failed with exit code 1.

If you are facing the issue with the following error:

CTC1014	Docker command failed with exit code 1.
The command 'cmd /S /C dotnet restore "projectname.csproj"' returned a non-zero code: 1

Ensure that you have selected Debug mode instead of Release.

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

.NET Core: UseUrls seems getting ignored error

If you are facing the issue, that the Host.CreateDefaultBuilder’s ConfigureWebHostDefaults’s UseUrls method is getting ignored, and all the environment variables and launchsettings.json completly getting ignored by the .NET core application, its always using the default port of http : 5000 and the https 5001, follow the instructions

Are you using configuration builder before calling the configurewebhostdefaults?

				ConfigurationBuilder cfgBuilder = new ConfigurationBuilder();
				cfgBuilder.AddEnvironmentVariables("CONFIGPREFIX_");
				IConfigurationRoot configuration = cfgBuilder.Build();

And are you passing the built configuration to ConfigureAppConfiguration ? Like that:

					.ConfigureAppConfiguration(builder =>
					{
						builder.Sources.Clear();
						builder.AddConfiguration(configuration);
					})

Then remove the ConfigureAppConfiguration call, and it will work..

No idea how to work around

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Docker error: CTC1015 Docker command failed with exit code 125.

If the Visual Studio’s output of the build on windows says the following:

docker: Error response from daemon: failed to create endpoint <ProjectName> on network nat: failed during hnsCallRawResponse: hnsCall failed in Win32: The process cannot access the file because it is being used by another process. (0x20).
If the error persists, try restarting Docker Desktop.

Solution

Go to your Services administration panel (by running services.msc)

Stop the following services:
– HNS (Host Network Service)
– docker (Docker Engine)

Then restart them in the order of stopping.

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Windows: Set Environment variables for users

For some cases you might need to set environment variables for your .NET application.
This is true to .NET core too, when you are storing your application settings in these variables.

How to set up a script for the job

It’s handy to create a windows command line script for creating these variables, because when you are on a new work environment, than you don’t need to look up the keys and values.

So bring up your most-loved text editor, make your environment_variable_creator.bat, and add the following code:

@echo on
SETX VARIABLE1 VALUE
SETX PREFIX_VARIABLE2 true
pause

If you are using .NET core’s configuration builder with a prefix like this:

				ConfigurationBuilder cfgBuilder = new ConfigurationBuilder();
				cfgBuilder.AddEnvironmentVariables("PREFIX_");
				IConfigurationRoot configuration = cfgBuilder.Build();
				var value = configuration["VARIABLE2"];

Then you need to set your variables with prefix “PREFIX_” in the bat file. In this scenario, VARIABLE1 can not be read, because it does not contain the prefix.

The code sets the variables only for your user account, not for others. You can parameterize the SETX command to set the settings for a different user, but i recommend, to run the script with a command line for the targeted user, because its much easier.

To run your script under other users name, then open your command prompt with ‘Run as… different user’

This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

.NET Core: Using AssemblyInfo shared between assemblies

There was a time when project.json has replaced the AssemblyInfo. But since .NET core uses .csproj, instead of the project.json, AssemblyInfo comes to the development again.

If you want to version your several different assemblies together, then follow this tutorial.

Add a shared AssemblyInfo.cs

Right click on your solution, and select Add > New Item..

In the following screen, select Visual C# class, and name it as ‘AssemblyInfo.cs’

Replace the file content with the example below:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyDescription("Insert your description here")]
[assembly: AssemblyCompany("YourAwesomeCompany")]
[assembly: AssemblyCopyright("Copyright © YourAwesomeCompany 2021")]

Set your projects to use the shared assembly info

Do this all of your projects where you want to use the shared assembly info file.

Edit your project file with a text editor (or right click on project > Edit project file)

Add the following tag to the PropertyGroup tag in order to diable automatic assemblyinfo.cs generation:

<PropertyGroup>
....
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
....
</PropertyGroup>

Add the shared assembly info to be used with inserting the following tags to between the project tags:

  <ItemGroup>
    <Compile Include="..\AssemblyInfo.cs" Link="Properties\AssemblyInfo.cs" />
  </ItemGroup>

If the project has no Properties folder, like .NET Standard projects basically do, then add the new folder also with this snippet:

  <ItemGroup>
    <Folder Include="Properties\" />
  </ItemGroup>
This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.