Use project link in Debug and Nuget in release

I would like to work in my project (A) and the dependent Nuget package (B) at the same time, without having to release the nuget package with every change.

Is it possible to execute the project link of the Nuget project (B) from solution (A) when building Debug. And when creating Release, use the Nuget package from Source?

+10
source share
3 answers

One way is to manually edit the csproj file. If you are currently referencing a NuGet package, you will have a part in the csproj file as follows:

....
<ItemGroup>
  <Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
    <HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
    <Private>True</Private>
  </Reference>
  <Reference Include="System" />
  <Reference Include="System.Core" />
  <Reference Include="System.Xml.Linq" />
  <Reference Include="System.Data.DataSetExtensions" />
  <Reference Include="Microsoft.CSharp" />
  <Reference Include="System.Data" />
  <Reference Include="System.Xml" />
</ItemGroup>
....

log4net. NuGet , .. . :

  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <Reference Include="log4net">
      <HintPath>Debug\log4net.dll</HintPath>
      <Private>True</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
      <HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
      <Private>True</Private>
    </Reference>
  </ItemGroup>

Condition ItemGroup .

+7

- Nuget (B) (A) Debug. Release Nuget Source?

, , .

, NuGet , NuGet . (, TestProjectReferenceForDebug - , NuGet, NuGet , , NuGet "TestNuGetForRelease" ):

enter image description here

, Condition ItemGroup, 'TestProjectReferenceForDebug' 'TestNuGetForRelease', Condition ItemGroup

  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <Reference Include="TestNuGetForRelease, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" >
      <HintPath>..\packages\TestNuGetForRelease.1.0.0\lib\net462\TestNuGetForRelease.dll</HintPath>
      <Private>True</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
     <ProjectReference Include="..\TestProjectReferenceForDebug\TestProjectReferenceForDebug.csproj">
       <Project>{90424b17-2231-4d7d-997b-608115d9f4d9}</Project>
       <Name>TestProjectReferenceForDebug</Name>
     </ProjectReference>
  </ItemGroup>

, Condition ItemGroup debug release debug Nuget release, , .cs , , " " xxx " ". , VS "Release" "Debug":

enter image description here

, , , Debug Release.

enter image description here

+3

.NET Core (2.x ++)

.NET Core 2.x !

A B, A .NET Standard Core (Properties → Package Package id Package id NuGet), .csproj:

<ItemGroup>
  <ProjectReference Include="..\..\A\ProjectA.csproj" />
</ItemGroup>

( dotnet pack) B - Package id A, .nuspec NuGet NuGet, , DLL.

<dependencies>
  <group targetFramework=".NETStandard2.0">
    <dependency id="Project.A" version="1.2.3" exclude="Build,Analyzers" />
    <dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
  </group>
</dependencies>
0

Source: https://habr.com/ru/post/1681098/


All Articles