-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom conditional dotnet add package
#8741
Comments
You can achieve a similar effect using the Condition attribute for MSBuild ItemGroup elements. For example: <PropertyGroup>
<Env Condition="'$(Env)' == ''">Development</Env>
</PropertyGroup>
<ItemGroup Condition="'$(Env)' == 'Production'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(Env)' == 'Development'">
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="3.0.250" />
<PackageReference Include="LigerShark.WebOptimizer.Sass" Version="3.0.40-beta" />
<PackageReference Include="LigerShark.WebOptimizer.TypeScript" Version="2.5.10-beta" />
</ItemGroup> When you add packages via dotnet add package NuGet.Protocol It will add the package to the ItemGroup conditioned for the 'Development' ItemGroup, since it is the default value for the Env property, as defined in the PropertyGroup: <PropertyGroup>
<Env Condition="'$(Env)' == ''">Development</Env>
</PropertyGroup>
<ItemGroup Condition="'$(Env)' == 'Production'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(Env)' == 'Development'">
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="3.0.250" />
<PackageReference Include="LigerShark.WebOptimizer.Sass" Version="3.0.40-beta" />
<PackageReference Include="LigerShark.WebOptimizer.TypeScript" Version="2.5.10-beta" />
<PackageReference Include="NuGet.Protocol" Version="5.3.1" />
</ItemGroup> In that case, you will need to manually edit the .csproj file for adding the PackageReference for different ItemGroup's |
dotnet add package
Hello! I have the same problem, but the workaround doesn't work when the nuget package is already added, and only need to update the package. When I try to use an another workaround with
The We use internal (company) nuget packages and build with Azure Devops Server and only can use dotnet cli. :( |
dotnet add package
dotnet add package
for instance:
This will avoid binary size when publish project and will avoid environment condition in Startup.cs
The text was updated successfully, but these errors were encountered: