I'm trying to use a project configuration where i switch between ProjectReferences en PackageReferences depending on Debug or Release build.
The .csproj looks like this:
<ItemGroup Condition="'$(Configuration)' == 'Release'">
<PackageReference Include="Xploration.Core" Version="0.1.0" />
<PackageReference Include="Xploration.TransientFaultHandling" Version="0.1.0" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
<ProjectReference Include="..\Xploration.Core\Xploration.Core.csproj" />
<ProjectReference Include="..\Xploration.TransientFaultHandling\Xploration.TransientFaultHandling.csproj" />
</ItemGroup>
The referenced projects are within the same solution so during development i can debug and modify the referenced projects. When i switch to release, the referenced projects are build, packed and pushed to a local nuget feed so they can be used as PackageReference after that.
Sadly, this doesn't work, as the PackageReferences are not restored during release build, but instead i see visual studio resolving those references by project.
Any ideas ?
@davkean how does the project system handle switching these values and evaluating this?
When i switch between "Release" mode and "Debug" mode visually it looks like this in the solution explorer:
Debug Mode:

Release Mode:

I don't know if this is helpful, but the project is a multi target classlibrary targetting netstandard1.6 and net45.
@XplMarcel if you right click on the solution and select restore nuget packages does it update things?
@emgarten The Package Manager output shows the following:
Restoring NuGet packages...
Restoring packages for D:\Projects\Xploration\Sources\ClassLibraries\Xploration.Data\Xploration.Data.csproj...
Lock file has not changed. Skipping lock file write. Path: D:\Projects\Xploration\Sources\ClassLibraries\Xploration.Data\obj\project.assets.json
Restore completed in 481,82 ms for D:\Projects\Xploration\Sources\ClassLibraries\Xploration.Data\Xploration.Data.csproj.
Committing restore...
The solution explorer however doesn't show any changes at all.
I even tried to see if clearing the nuget cache before opening VS 2017 and the solution made any differences at all, but the outcome is the same.
If i try to rebuild the solution in Release mode i also get a ton of errors which indicate that those 2 faulting package references are not being resolved at all.
Tomorrow morning i will try to setup a sample solution in case a repro of the problem is needed.
I have same issue, dotnet restore does not restore when PackageReference has a build condition
for eg.
<PackageReference Include="ABC.Serialization.NetCore" Version="1.0.0.12614" Condition="'$(Configuration)' == 'ProductionNew'">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
does not restore the lib and the compilation ends us with an error. Seems like Nuget restore needs to be build system / configuration aware
after a bit of testing i found out that we need to pass additional parameter to the restore command
for eg
dotnet restore ABC.csproj /p:Configuration=ProductionNew
For issues with Visual Studio not respecting conditions see: https://github.com/dotnet/project-system/issues/1542
For issues with conditions from the command line see the comment from @samirparekh
Most helpful comment
When i switch between "Release" mode and "Debug" mode visually it looks like this in the solution explorer:
Debug Mode:
Release Mode:
I don't know if this is helpful, but the project is a multi target classlibrary targetting netstandard1.6 and net45.