Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Dotnet new extra arguments do not work with custom dotnet library template #783

Closed
md-owes opened this issue Oct 21, 2023 · 2 comments · Fixed by #788
Closed

[BUG] Dotnet new extra arguments do not work with custom dotnet library template #783

md-owes opened this issue Oct 21, 2023 · 2 comments · Fixed by #788
Labels
bug Something isn't working outdated scope: core

Comments

@md-owes
Copy link

md-owes commented Oct 21, 2023

Current Behavior

I have created two custom dotnet templates. one named "jaamapi" which is a template to create custom dotnet webapi project and another named "jaamdom" to create custom dotnet library project. Both templates require additional arguments to be passed. When i execute these commands directly as dotnet commands, they work as shown below

dotnet new jaamapi -n ProgramService.API -N ProgramService -E Program -L program
dotnet new jaamdom -n ProgramService.Domain -o Domain -N ProgramService -E Program -L program

But when executing these commands via nx-dotnet, the first command executes successfully and provides the expected output whereas the second fails to execute with an error as shown in Failure Logs section.

Nx Dotnet command that

works

nx g @nx-dotnet/core:app --name ProgramService --tags ps --directory ProgramService --template jaamapi --language C# --skipSwaggerLib true --pathScheme dotnet --testTemplate none --verbose --args='-N=ProgramService,-E=Program,-L=program'

throws below error

nx g @nx-dotnet/core:lib --name Domain --tags ps --directory ProgramService --template jaamdom --language C# --skipSwaggerLib true --pathScheme dotnet --testTemplate none --verbose --args='-N=ProgramService,-E=Program,-L=program'

From error it is evident that the nx-dotnet library does not parse the additional arguments the same way as the nx-dotnet application works.

Expected Behavior

The library creation command using nx, i.e. @nx-dotnet/core:lib, should work with additional arguments just the way @nx-dotnet/core:app works.

Github Repo

No response

Steps to Reproduce

  1. you need to create two custom dotnet templates as mentioned in MSDN docs
  2. once the templates are created and installed locally on your system, you can test it using dotnet new command
  3. Once the previous step is successful, now execute nx-dotnet commands for both templates, you need to ensure that first nx command should be an application and the other a library
  4. Now, you can observe that the library command fails with similar error as mentioned in description

Nx Report

NX   Report complete - copy this into the issue template

   Node   : 20.8.0
   OS     : win32-x64
   npm    : 10.1.0

   nx (global)    : 16.9.1
   nx             : 16.9.1
   @nx/js         : 16.9.1
   @nx/linter     : 16.9.1
   @nx/workspace  : 16.9.1
   @nx/devkit     : 16.9.1
   @nrwl/devkit   : 15.8.5
   @nrwl/tao      : 16.9.1
   nx-cloud       : 16.4.0
   typescript     : 4.9.5
   ---------------------------------------
   Community plugins:
   @nx-dotnet/core : 1.23.0
   ---------------------------------------
   The following packages should match the installed version of nx
     - @nrwl/devkit@15.8.5

   To fix this, run `nx migrate nx@16.9.1`

nx.json

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "tasksRunnerOptions": {
    "default": {
      "runner": "nx/tasks-runners/default",
      "options": {
        "cacheableOperations": [
          "build",
          "lint",
          "test",
          "e2e",
          "codegen",
          "swagger"
        ]
      }
    }
  },
  "targetDefaults": {
    "build": {
      "dependsOn": [
        "^build",
        "codegen",
        "^codegen"
      ],
      "inputs": [
        "production",
        "^production"
      ]
    },
    "lint": {
      "inputs": [
        "default",
        "{workspaceRoot}/.eslintrc.json",
        "{workspaceRoot}/.eslintignore"
      ]
    },
    "test": {
      "inputs": [
        "default",
        "^production",
        "{workspaceRoot}/jest.preset.js"
      ]
    }
  },
  "namedInputs": {
    "default": [
      "{projectRoot}/**/*",
      "sharedGlobals"
    ],
    "production": [
      "default",
      "!{projectRoot}/.eslintrc.json",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.[jt]s",
      "!{projectRoot}/src/test-setup.[jt]s",
      "!{projectRoot}/test-setup.[jt]s"
    ],
    "sharedGlobals": []
  },
  "plugins": [
    "@nx-dotnet/core"
  ]
}

Failure Logs

NX  Generating @nx-dotnet/core:library

Executing Command: dotnet "new" "jaamdom" "--language" "C#" "--name" "ProgramService.Domain" "--output" "program-service/Domain" "-" "N" "=" "P" "r" "o" "g" "r" "a" "m" "S" "e" "r" "v" "i" "c" "e" "," "-" "E" "=" "P" "r" "o" "g" "r" "a" "m" "," "-" "L" "=" "p" "r" "o" "g" "r" "a" "m"
Error: Invalid option(s):
-
   '-' is not a valid option
N
   'N' is not a valid option
=
   '=' is not a valid option
P
   'P' is not a valid option
r
   'r' is not a valid option
o
   'o' is not a valid option
g
   'g' is not a valid option
a
   'a' is not a valid option
m
   'm' is not a valid option
S
   'S' is not a valid option
e
   'e' is not a valid option
v
   'v' is not a valid option
i
   'i' is not a valid option
c
   'c' is not a valid option
,
   ',' is not a valid option
E
   'E' is not a valid option
L
   'L' is not a valid option
p
   'p' is not a valid option

For more information, run:
   dotnet new jaamdom --language C# -h

For details on the exit code, refer to https://aka.ms/templating-exit-codes#127

NX   dotnet execution returned status code 127


Error: dotnet execution returned status code 127
    at DotNetClient.logAndExecute (E:\REPO\ADO\Jaameah\JaameahBack\node_modules\@nx-dotnet\dotnet\src\lib\core\dotnet.client.js:230:19)
    at DotNetClient.new (E:\REPO\ADO\Jaameah\JaameahBack\node_modules\@nx-dotnet\dotnet\src\lib\core\dotnet.client.js:21:21)
    at E:\REPO\ADO\Jaameah\JaameahBack\node_modules\@nx-dotnet\core\src\generators\utils\generate-project.js:116:25
    at Generator.next (<anonymous>)
    at fulfilled (E:\REPO\ADO\Jaameah\JaameahBack\node_modules\tslib\tslib.js:166:62)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Additional Information

I have tried to play around with additional argument syntax as shown

nx g @nx-dotnet/core:lib --name Domain --tags ps --directory ProgramService --template jaamdom --language C# --skipSwaggerLib true --pathScheme dotnet --testTemplate none --verbose --args='-N ProgramService,-E Program,-L program'

nx g @nx-dotnet/core:lib --name Domain --tags ps --directory ProgramService --template jaamdom --language C# --skipSwaggerLib true --pathScheme dotnet --testTemplate none --verbose --args='-N ProgramService -E Program -L program'

nx g @nx-dotnet/core:lib --name Domain --tags ps --directory ProgramService --template jaamdom --language C# --skipSwaggerLib true --pathScheme dotnet --testTemplate none --verbose --args '-N ProgramService -E Program -L program'

nx g @nx-dotnet/core:lib --name Domain --tags ps --directory ProgramService --template jaamdom --language C# --skipSwaggerLib true --pathScheme dotnet --testTemplate none --verbose -- '-N ProgramService -E Program -L program'

nothing worked so far.

@md-owes md-owes added bug Something isn't working needs-triage This issue has yet to be looked over by a core team member labels Oct 21, 2023
@AgentEnder AgentEnder added scope: core and removed needs-triage This issue has yet to be looked over by a core team member labels Oct 25, 2023
github-actions bot pushed a commit that referenced this issue Oct 25, 2023
# [2.1.0](v2.0.2...v2.1.0) (2023-10-25)

### Bug Fixes

* **core:** should be able to pass extra args to generated libraries ([#788](#788)) ([2d2cb5b](2d2cb5b)), closes [#783](#783)

### Features

* **core:** better configuration options for target inference ([#787](#787)) ([8a7b9a1](8a7b9a1))

Oct 25, 2023, 5:38 PM
@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working outdated scope: core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants