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

[Feature] Generate Directory.Build.props during init generator #469

Closed
AgentEnder opened this issue Jul 13, 2022 · 6 comments
Closed

[Feature] Generate Directory.Build.props during init generator #469

AgentEnder opened this issue Jul 13, 2022 · 6 comments
Labels

Comments

@AgentEnder
Copy link
Member

Current Behavior

Currently, we set the output path of C# projects in the monorepo individually. We do this by manually specifying them in each .csproj file. This has issues.

Desired Behavior

During @nx-dotnet/core:init, we should scaffold a minimal Directory.Build.props file that contains the setup for output paths.

Additional context
We need to ensure that the creation of this file is idempotent. init is called automatically at the beginning of each project generator, and the file shouldn't be recreated each time in case dev's customize it.

@AgentEnder AgentEnder added enhancement New feature or request needs-triage This issue has yet to be looked over by a core team member scope: core and removed needs-triage This issue has yet to be looked over by a core team member labels Jul 13, 2022
@tzuge
Copy link
Contributor

tzuge commented Jul 22, 2022

I am currently setting up dotnet projects in a monorepo to better understand this. For 'app' vs 'lib', the output path is different in nx convention, and this appears to be achievable with dotnet by checking the SDK.

  <PropertyGroup Condition="'$(UsingMicrosoftNETSdkWeb)' == 'false'">
    <BaseOutputPath>$(RepoRoot)dist/libs/$(MSBuildProjectName)</BaseOutputPath>
  </PropertyGroup>

  <PropertyGroup Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true'">
    <BaseOutputPath>$(RepoRoot)dist/apps/$(MSBuildProjectName)</BaseOutputPath>
  </PropertyGroup>

@AgentEnder
Copy link
Member Author

AgentEnder commented Jul 25, 2022

That's interesting too, but the workspace layout is determined by a property in nx.json. Ideally, we should read nx.json to determine the apps/libs folders when creating this file. @nrwl/devkit exports readWorkspaceConfiguration, which we can access the appsDir / libsDir with.

During init, we could use it to update these.

At the same time though, I'm not really a fan of checking for the .NET web SDK here... Console applications as an example would not be picked up. Nx traditionally classifies e2e as an app, which this would miss etc. Perhaps it would be better to not bother with libs/apps directory in the output path. Do something like:

  <PropertyGroup>
    <BaseOutputPath>$(RepoRoot)dist/nx-dotnet/$(MSBuildProjectName)</BaseOutputPath>
  </PropertyGroup>

@tzuge
Copy link
Contributor

tzuge commented Jul 28, 2022

Agreed about using appsDir / libsDir from the workspace config during init creation of the Directory.Build.* files. Regarding excluding apps / libs from the output path, I feel like that's not ideal since it's different from the non-dotnet projects.

Is there currently a generator that results in a project with IsPackable set to true? Although I suppose that really maps to "publishable libs" and not "libs"; perhaps should be the result in case of nx g @nx-dotnet/core:classlib --publishable.

@AgentEnder
Copy link
Member Author

There is a different strategy to this that I've thought of that would match typical Nx dist output better. If we could represent ${workspaceRoot}/dist/${projectRoot} in the Directory.Build.Props file than that would match up better than what we've been discussing.

There's not the concept of a publishable lib in nx-dotnet, the generators don't do a ton of extra stuff beyond dotnet new aside from

  • Setting up prebuild module boundaries task
  • Setting up dist folder outputs

@tzuge
Copy link
Contributor

tzuge commented Jul 28, 2022

Great idea. This seems to work.

<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))</RepoRoot>
<BaseOutputPath>$(RepoRoot)dist/$([System.IO.Path]::GetRelativePath($(RepoRoot), $(MSBuildProjectDirectory)))</BaseOutputPath>

@github-actions
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 Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants