Question:
Share class source code between several solutions with nuget references


Solution

There are a few ways to solve this, but adding different hint paths depending on conditions—like in the example below—is among the simplest and most effective ones.


<Reference Include="TheAssembly">

    <HintPath Condition="Exists('..\My\Assembly\Path')">..\My\Assembly\Path\TheAssembly.dll</HintPath>

    <HintPath Condition="Exists('..\..\My\Assembly\Path')">..\..\My\Assembly\Path\TheAssembly.dll</HintPath>

    <HintPath Condition="Exists('..\..\..\My\Assembly\Path')">..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>

    <HintPath Condition="Exists('..\..\..\..\My\Assembly\Path')">..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>

    <HintPath Condition="Exists('..\..\..\..\..\My\Assembly\Path')">..\..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>

    <HintPath Condition="Exists('..\..\..\..\..\..\My\Assembly\Path')">..\..\..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>

    <HintPath Condition="Exists('..\..\..\..\..\..\..\My\Assembly\Path')">..\..\..\..\..\..\..\My\Assembly\Path\TheAssembly.dll</HintPath>

    etc...

</Reference>


The question ".csproj multiple hint paths for an assembly" inspired this solution.

Another option—which might be preferable—is to use the common class library package as a Nuget package.


Suggested blogs

>>Why it is must to use a forward slash in the ASP.NET Core API?

>>Using Fetch in JS to call a server-side method (ASP.NET)

>>How to Prevent Repeated Execution of ASP.NET Button Click?

>>Fix Asp.net issue: AjaxControlToolkit FileUpload not working

>>Fix ASP.NET Core Model Binding Not Working issue

>>Changing main page as Identity's Login page in ASP.NET Core 7

>>CRUD Operations In ASP.NET Core Using Entity Framework Core Code First with Angularjs

>>Built Web API using ASP.NET (C#)

>>Use Firebase Realtime Database with ASP.NET MVC App


Ritu Singh

Ritu Singh

Submit
0 Answers