CleanArchitecture icon indicating copy to clipboard operation
CleanArchitecture copied to clipboard

Cannot build WebUI. Compile error

Open workingacc123 opened this issue 2 years ago • 3 comments

Describe the bug Build fails. There is a problem with Nswag package. Currently i am on 13.16.0 NSwag version.

To Reproduce Steps to reproduce the behavior:

  1. Change the useinmemorydatabase variable to false in WebUI/appsettings.json => "UseInMemoryDatabase": false. image

  2. Change the Default connection string to proper one(the connection string is trustworthy and there isn't a problem with it).

  3. Build the project

Expected behavior The code to work properly

Screenshots image

workingacc123 avatar Sep 07 '22 13:09 workingacc123

I can't identity the issue based on the description provided. I tried the following:

dotnet new ca-sln
dotnet build

The solution creates and builds successfully. NSwag runs without error.

Update WebUI/appsettings.json as follows:

{
-  "UseInMemoryDatabase": false,
+  "UseInMemoryDatabase": true,
   "ConnectionStrings": {
      "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=CaSlnTest01Db;Trusted_Connection=True;MultipleActiveResultSets=true;"
    },

The default connection string is using LocalDb, so I left that alone.

dotnet build

The solution builds again without error, and the output indicates database interaction. NSwag runs normally.

Try checking Output for more information.

jasontaylordev avatar Sep 13 '22 10:09 jasontaylordev

I have the same issue.

Setting the "UseInMemoryDatabase" to false allows the build to complete but if you provide your own connection string and set the "UseInMemoryDatabase" to false (as we want to use the DB from the connection string) the build will fail as outlined by @workingacc123

YARG avatar Sep 15 '22 15:09 YARG

OK I got it working. I commented out:

<Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' "> <Exec WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net60) run nswag.json /variables:Configuration=$(Configuration)" /> </Target>

which let me then build and run the project, it then failed on the migration step.

My connection string (Azure SQL) was wrong and I also had to add "Microsoft.Data.SqlClient" due to the error:

[Invalid value for key 'authentication'](https://stackoverflow.com/questions/59654712/invalid-value-for-key-authentication)

I was then able to run the project fine (created the tables in Azure). I then uncommented the above and I was still able to build and run the project still. So for me it was simply down to an invalid connection to the SQL Azure DB "my bad" and the addition of "Microsoft.Data.SqlClient". I hope it helps.

YARG avatar Sep 15 '22 15:09 YARG

OK I got it working. I commented out:

<Target Name="NSwag" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' "> <Exec WorkingDirectory="$(ProjectDir)" EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net60) run nswag.json /variables:Configuration=$(Configuration)" /> </Target>

which let me then build and run the project, it then failed on the migration step.

My connection string (Azure SQL) was wrong and I also had to add "Microsoft.Data.SqlClient" due to the error:

[Invalid value for key 'authentication'](https://stackoverflow.com/questions/59654712/invalid-value-for-key-authentication)

I was then able to run the project fine (created the tables in Azure). I then uncommented the above and I was still able to build and run the project still. So for me it was simply down to an invalid connection to the SQL Azure DB "my bad" and the addition of "Microsoft.Data.SqlClient". I hope it helps.

I was looking far and wide to see why nswag wasn't generating client side. lol Nswag being commented out isn't the issue. I have the 7.0 release of this project and added what you commented out and it got built. I solved all my problems sigh.I think the problem is you didn't update your NSwag package.

hrrysnplusplus avatar Nov 03 '22 00:11 hrrysnplusplus

Hopefully, with recent changes to the way NSwag runs in the template, these kinds of issues will be easier to detect.

jasontaylordev avatar Feb 23 '23 10:02 jasontaylordev

it happens only in Develop builds. you can use dotnet build sample.csproj -c Release instead

Sam4n avatar Apr 01 '24 20:04 Sam4n