I am migrating my web application from .Net Core 1.1
to 2.0
, and has tried to make it more compatible by ensuring it works both under 1.1 and 2.0.
When it comes to making the project packages automatically adapt to the current switched version, I used <Choose/>
and <When/>
tags in .csproj file like this:
<Choose>
<When Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<ItemGroup>
<PackageReference Include="..." Version="1.1.2" />
<!-- Some package references -->
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.0-preview4-final" />
</ItemGroup>
</When>
<When Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
</When>
</Choose>
This works fine with <PackageReference/>
s, with application well compiled and run under specified $(TargetFramework)
.
However, the dotnet cli tools seems to be "missing" from the project by this action. After executing dotnet restore
command, I tried dotnet ef database udpate
command, end up receiving this message:
No executable found matching command "dotnet-ef"
Yet when I took the <DotNetCliToolReference/>
s out of <Choose></Choose>
tag and run dotnet restore
, everything behaved well as before.
So, What's the matter with these tags when running in dotnet-cli? Is there anything I can do to make my dotnet-cli ItemGroup automatically changes according to $(TargetFramework)
?