I got exception after adding automatic configuration generation in C# project

19 hours ago 4
ARTICLE AD BOX

I want to make certification when building application instead of manually creating it. I wrote a script to generate certificate and then call it from my .csproj file. But the problem is: when I run the first build, it returns an error; but the next time (after generation of certificate from failed build (there are certificate can see in project)) onwards, there is no error, and it is running smoothly.

Here are the details - this is in my .csproj file:

<Target Name="SetupCertificate" BeforeTargets="PreBuildEvent"> <Exec Command="call $(ProjectDir)setup-certificate.bat" /> </Target>

This is the error I get:

Exception in Command Processing for EventSource Dotnet-dev-certs: Event WslWindowsTrustSucceeded was assigned event ID 115 but 113 was passed to WriteEvent.

The command "call C:\path\to\file\setup-certificate.bat" exited with code -1.

Here's the batch file:

@echo off :: Define certificate in project directory set "CERT_FILE=%~dp0server.pfx" set "CERT_PASSWORD=my_test_pwd" :: Check if certificate already exists if exist "%CERT_FILE%" ( echo [INFO] Certificate already exists: server.pfx - Skipping setup. exit /b 0 ) echo [INFO] Generating development certificate... dotnet dev-certs https -ep "%CERT_FILE%" -p "%CERT_PASSWORD%" 2>nul if errorlevel 1 ( echo [ERROR] Failed to generate certificate! exit /b 1 ) echo [INFO] Certificate generated successfully! :: Trust the certificate (ignore exit code as it can return -1 even on success) echo [INFO] Trusting the certificate... dotnet dev-certs https --trust 2>nul || echo [INFO] Certificate trust completed (you may see a prompt) :: Update appsettings.json echo [INFO] Updating appsettings.json... set "APPSETTINGS=%~dp0appsettings.json" powershell -Command "(Get-Content '%APPSETTINGS%') -replace '\"CertificatePassword\": \".*\"', '\"CertificatePassword\": \"%CERT_PASSWORD%\"' | Set-Content '%APPSETTINGS%'" 2>nul powershell -Command "(Get-Content '%APPSETTINGS%') -replace '\"CertificatePath\": \".*\"', '\"CertificatePath\": \"roommate-server.pfx\"' | Set-Content '%APPSETTINGS%'" 2>nul powershell -Command "(Get-Content '%APPSETTINGS%') -replace '\"EnableSSL\": false', '\"EnableSSL\": true' | Set-Content '%APPSETTINGS%'" 2>nul echo [INFO] Setup complete! Certificate: server.pfx, Password: %CERT_PASSWORD% exit /b 0
Read Entire Article