Problem With Publishing a Self Contained EXE (Issue With Nuget)

2k views Asked by At

I have created an application in c# using visual studio 2019. When I released it, everything worked fine but the exe came out with 2 other files in the folder. I want to have just one exe that can run by itself, without any extra files in its location, so I tried the "self contained" option in the publish settings. It didn't work though. I only get an "error has occured" popup window that says this:

Publish has encountered an error.
Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. 

A diagnostic log has been written to the following location:
"C:\Users\***\AppData\Local\Temp\tmp4E17.tmp"

And in the output box below I get this:

1>Determining projects to restore...
1>Unable to load the service index for source 
https://api.nuget.org/v3/index.json.
1>  An error occurred while sending the request.
1>  The request was aborted: Could not create SSL/TLS secure 
channel.
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped 
==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

Now, I've seen some similar issues that people posted about this and some possible fixes, but nothing has worked for me. I have updated TLS 1.3->Client->DisabledByDefault value to 1 in regedit and it still didn't fix the problem.

I'm using system windows 7 (32-bit). I'm looking forward to any possible fixes, thank you in advance.

2

There are 2 answers

1
Mr Qian On

First, please check if the problem is related to network or VS IDE.

Please enter the link https://api.nuget.org/v3/index.json on the website and if you cannot open the website, I think the issue is related to your Internet and you should check your Internet and make sure that there is nothing else breaking it.

If not, I think the issue is related to VS IDE. You should try the following steps:

1) disable any third party vs installed extensions under Extensions-->Manage Extensions to check if there is an extension cause that.

2) clean all nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages

3) enable only nuget.org nuget package source and disable the others.

Enter Tools-->Options-->Nuget Package Manager-->Package Sources

enter image description here

Uncheck the other package sources and only remain nuget.org.

Besides, you can also change nuget.org package source as http://packages.nuget.org/v1/FeedService.svc/ or https://nuget.org/api/v2/ to test whether it can resore nuget packages.

4) close VS, delete the global nuget.config file under C:\Users\xxx(current user)\AppData\Roaming\NuGet. Then, restart your VS to regenerate the file, test again.

5) run these under CMD( run as Administrator)

reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:64
reg add HKLM\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 /v SystemDefaultTlsVersions /t REG_DWORD /d 1 /f /reg:32

6) repair VS or update it to the latest version

0
Lukasz Szczygielek On

I have same issue - Visual Studio 2019 but Windows 7 64 bit. I can't publish using a self-contained deployment mode under Visual Studio. I didn't found solution, but workaround is available.

Workaround

Publish from command line works. During first run nuget will be downloaded to local cache, so after this publish under Visual Studio will work too. Example:

dotnet publish ProjectName.csproj /p:PublishProfile=YourPublishProfileName

Other possible workaround

Use Windows 10. I moved project to PC with same Visual Studio, but with Windows 10. Publish from Visual Studio works without issues.