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

Question: How can I create a "soft dependency" between 2 projects #5482

Closed
TFTomSun opened this issue Jul 3, 2020 · 3 comments
Closed

Question: How can I create a "soft dependency" between 2 projects #5482

TFTomSun opened this issue Jul 3, 2020 · 3 comments
Labels

Comments

@TFTomSun
Copy link

TFTomSun commented Jul 3, 2020

Let's assume I have project A and project B. They have different incompatible TargetFrameworks, but the build of A depends on the build of B. I want to keep the delta compile compatibility, too. That means:

  • no changes to both projects -> no build
  • change in B -> Build of A triggers build of B first, then builds A
  • change in A -> Only A builds

Is there a common approach to achieve that for all kind of SDK-style projects?

@xerif
Copy link

xerif commented Jul 7, 2020

You can set project A to be dependent on B, without actually referencing B, using ProjectReference with:

  • ReferenceOutputAssembly set to false
  • SkipGetTargetFrameworkProperties set to true

This is loosely based on #3843

<!-- ProjectA.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net20</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\ProjectB\ProjectB.csproj">
      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
      <SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
    </ProjectReference>
  </ItemGroup>
</Project>
<!-- ProjectB.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>
</Project>

This appears to fit your requirements, so:

  • projects are incompatible (net20 cannot reference netstandard2.1)
  • when changing something in A:
    • and building A => only A builds
    • and building B => nothing builds
  • when changing something in B:
    • and building A => only B builds (nothing changed in A, so A doesn't)
    • and building B => only B builds

@TFTomSun
Copy link
Author

TFTomSun commented Jul 7, 2020

@xerif thanks alot! SkipGetTargetFrameworkProperties was the property I didn't know before.

@rainersigwald
Copy link
Member

Thanks @xerif! Closing this as that was a great answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants