Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution 0.2.0-alpha.2

Suggested Alternatives

Compze.Build.FlexRef

This is a prerelease version of Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution --version 0.2.0-alpha.2
                    
NuGet\Install-Package Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution -Version 0.2.0-alpha.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution" Version="0.2.0-alpha.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution" Version="0.2.0-alpha.2" />
                    
Directory.Packages.props
<PackageReference Include="Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution --version 0.2.0-alpha.2
                    
#r "nuget: Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution, 0.2.0-alpha.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution@0.2.0-alpha.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution&version=0.2.0-alpha.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Compze.Build.PackageReferenceOrProjectReferenceIfTargetInSolution&version=0.2.0-alpha.2&prerelease
                    
Install as a Cake Tool

PackageReferenceOrProjectReferenceIfTargetInSolution

Solution-aware MSBuild reference resolution for .NET projects.

The Problem

When a .NET solution contains many projects that are also published as NuGet packages, you face a choice:

  • ProjectReference — good for cross cutting development and refactoring across all projects, but requires all projects in the solution and builds are slow.
  • PackageReference — fast builds and lightweight solutions with any subset of projects, but you lose the above advantages.

Our Solution

Leverage MSBuild to make your references become project references if the referenced project is in the solution, and package references if not.

Then you can set up any number of solutions to fit what you need at the moment.

Installation

  1. Copy PackageReferenceOrProjectReferenceIfTargetInSolution.props into your repository (e.g. into a build/ folder).

  2. Import it from your Directory.Build.props (create the file if it doesn't exist):

<Project>
  <Import Project="$(MSBuildThisFileDirectory)build\PackageReferenceOrProjectReferenceIfTargetInSolution.props" />
</Project>

Workspace setup

1. Declare switchable dependencies in Directory.Build.props

After the import, add one property per switchable dependency:

  <PropertyGroup>
    <UsePackageReference_Acme_Utilities
        Condition="'$(UsePackageReference_Acme_Utilities)' != 'true'
                 And '$(_SwitchRef_SolutionProjects)' != ''
                 And !$(_SwitchRef_SolutionProjects.Contains('|Acme.Utilities.csproj|'))">true</UsePackageReference_Acme_Utilities>

    <UsePackageReference_Acme_Core
        Condition="'$(UsePackageReference_Acme_Core)' != 'true'
                 And '$(_SwitchRef_SolutionProjects)' != ''
                 And !$(_SwitchRef_SolutionProjects.Contains('|Acme.Core.csproj|'))">true</UsePackageReference_Acme_Core>
  </PropertyGroup>

Property name convention: UsePackageReference_{PackageName_with_dots_replaced_by_underscores}

2. Add conditional references in each .csproj

<ItemGroup Condition="'$(UsePackageReference_Acme_Utilities)' == 'true'">
  <PackageReference Include="Acme.Utilities" Version="3.1.0" />
</ItemGroup>
<ItemGroup Condition="'$(UsePackageReference_Acme_Utilities)' != 'true'">
  <ProjectReference Include="..\Acme.Utilities\Acme.Utilities.csproj" />
</ItemGroup>

Compatibility

Confirmed to work with:

  • Visual Studio 2026
  • JetBrains Rider
  • VS Code (C# Dev Kit and/or Resharper)
  • dotnet build / dotnet restore CLI

NCrunch Workaround

We have been unable to get automatic detection working with ncrunch. Our workaround is to set the required build properties in the ncrunch solution configuration.
That is: UsePackageReference_Acme_Utilities = true etc in My.slnx.v3.ncrunchsolution

CLI / CI Overrides

dotnet build /p:UsePackageReference_Acme_Utilities=true

License

Unlicense

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated