Paths /ASP.NET/Https and /Microsoft/UserSecrets) not shared on mac
This issue happens when you open, in Visual Studio for Mac, a project that was created using Visual Studio for Windows. Since most developers on my team are using Windows computers, I wanted to find a solution that would allow me to run the project without modifying its configuration. It required a lot of time and research, but I finally made it work:
Check if the folder
~/.aspnet/https
exists. If it does, skip to step 5.Create the folder structure
~./asp.net/https
.Run the command below to install the development certificates that allow you to access
localhost
through HTTPS. More details here.dotnet dev-certs https --trust
Run the command below to export the development certificate. Take note of the password as you will need it later:
dotnet dev-certs https -ep ${HOME}/.aspnet/https/FILE_NAME.pfx -p PASSWORD
Check if the folder
~/.microsoft/usersecrets
exists. If it does, it means you already have some User Secrets defined, so you can probably skip to step 7, otherwise, continue below.Get the User Secrets ID for the Assembly of the Web Application you're building. It is usually located in a file named like
Your.Project.Package.Name.Assembly.cs
. You can also search forUserSecrets.UserSecretsIdAttribute("
in your project folder and take the GUID.You might need to repeat this step for multiple assemblies in your solution if you're using Docker Compose to deploy more than one Web application at the same time.
Inside
~./microsoft/usersecrets
, create a folder with the GUID you got on step 6, assuming one does not exist already. If it does, you can simply update the filesecrets.json
inside it with the contents of the next step.Create the file
secrets.json
and insert the following:{ "Kestrel": { "Certificates": { "Default": { "Path": "/root/.aspnet/https/<FILE_NAME from Step 4>.pfx", "Password": "<PASSWORD from Step 4>" } } }}
Create a file named
.env
in the same folder where your Docker Compose configuration files are located inside the solution with the following content:APPDATA=/Users/YOUR_USER_NAME
This file will be picked up by Docker Compose automatically when Visual Studio runs the tool.
Add the file
.env
you just created to.gitignore
, so it doesn't get committed with your changes by mistake. This will ensure other developers with different environments can use this approach as well.Create a symbolic link to point
~/ASP.NET
to.aspnet
as follows:ln -s ~/.aspnet ~/ASP.NET
Create a symbolic link to point
~/ASP.NET/Https
to~/.aspnet/https
as follows:ln -s ~/.aspnet/https ~/ASP.NET/Https
Create a symbolic link to point
~/Microsoft
to~/.microsoft
as follows:ln -s ~/.microsoft ~/Microsoft
Create a symbolic link to point ~/Microsoft/UserSecrets
to
~/.microsoft/usersecrets` as follows:ln -s ~/.microsoft/usersecrets ~/Microsoft/UserSecrets
If you follow all steps correctly, Docker Compose will be able to resolve the Windows path in your Mac environment, find the required certificate password and run the solution correctly.
The outcome is that you only need to commit your .gitignore
changes to make sure your .env
file doesn't get included in the repo by mistake affecting others unintentionally - no further changes are required to the project.
Edit on August 4th, 2019: Some symlink creation parameters were in reverse order. Huge thanks to @BRBdot for pointing it out.
References:
As mentioned by @Leonardo Braga, this issue happens when you open, in Visual Studio for Mac, a project that was created using Visual Studio for Windows
I have used the following steps to solve this problem on Visual Studio Mac:
- Take the backup of the docker files and docker compose project, so to be in the safe side.
- Delete the docker files and the docker compose project from the solution and respective projects.
- Re-generate the docker files and docker compose by right click on the project and Add -> Add Docker Support
This is to me the easiest way to resolve the above issue.