C
C#6mo ago
Caedrius

Directory.Packages.props working for all projects except Api

I have the following Directory.Packages.props in my solution:
<Project>

<ItemGroup Condition="$(MSBuildProjectname.EndsWith('Api'))">
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
<PackageVersion Include="Swashbuckle.AspNetCore.Swagger" Version="6.4.0"/>
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Domain'))">
<PackageVersion Include="MediatR" Version="12.2.0" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Application'))">
<PackageVersion Include="FluentValidation" Version="11.8.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Infrastructure'))">
<PackageVersion Include="Autofac" Version="7.1.0" />
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageVersion Include="Polly" Version="8.2.0" />
</ItemGroup>

</Project>
<Project>

<ItemGroup Condition="$(MSBuildProjectname.EndsWith('Api'))">
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
<PackageVersion Include="Swashbuckle.AspNetCore.Swagger" Version="6.4.0"/>
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Domain'))">
<PackageVersion Include="MediatR" Version="12.2.0" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Application'))">
<PackageVersion Include="FluentValidation" Version="11.8.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Infrastructure'))">
<PackageVersion Include="Autofac" Version="7.1.0" />
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageVersion Include="Polly" Version="8.2.0" />
</ItemGroup>

</Project>
It works as expected for all projects in my solution expect my Api project. Any clues why?
No description
4 Replies
Caedrius
CaedriusOP6mo ago
I've already ruled out Rider as being the issue, same problem occurs in Visual Studio 2022. What makes this even weirder is that project references in my Directory.Build.targets works just fine. It seems to fail for any project using the web SDK
Caedrius
CaedriusOP6mo ago
Still failing for some reason :shrug:
<Project>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('Api'))">
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Domain'))">
<PackageVersion Include="MediatR" Version="12.2.0" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Application'))">
<PackageVersion Include="FluentValidation" Version="11.8.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Infrastructure'))">
<PackageVersion Include="Autofac" Version="7.1.0" />
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageVersion Include="Polly" Version="8.2.0" />
</ItemGroup>

</Project>
<Project>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('Api'))">
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Domain'))">
<PackageVersion Include="MediatR" Version="12.2.0" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Application'))">
<PackageVersion Include="FluentValidation" Version="11.8.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="$(MSBuildProjectName.EndsWith('BuildingBlocks.Infrastructure'))">
<PackageVersion Include="Autofac" Version="7.1.0" />
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageVersion Include="Polly" Version="8.2.0" />
</ItemGroup>

</Project>
No description
Caedrius
CaedriusOP6mo ago
So I don't need to reference any packages in the csproj files. Well I replaced PackageVersion with PackageReference and now it works
Caedrius
CaedriusOP6mo ago
i'm a dumbass that's why
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Configurations>Debug;Production</Configurations>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>false</Nullable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Deterministic>true</Deterministic>
<RestoreIgnoreFailedSource>true</RestoreIgnoreFailedSource>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<RunAnalyzersDuringLiveAnalysis>True</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzersDuringBuild>True</RunAnalyzersDuringBuild>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<Optimize>True</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Label="ConfigFiles">
<EditorConfigFile Condition=" '$(EditorConfigFile)' == '' ">$([MSBuild]::GetPathOfFileAbove('.editorconfig',
$(MSBuildProjectDirectory)))
</EditorConfigFile>
</PropertyGroup>

<ItemGroup Label="ConfigFiles">
<None Condition="Exists('$(EditorConfigFile)')" Include="$(EditorConfigFile)" Visible="false"/>
</ItemGroup>

</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Configurations>Debug;Production</Configurations>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>false</Nullable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Deterministic>true</Deterministic>
<RestoreIgnoreFailedSource>true</RestoreIgnoreFailedSource>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<RunAnalyzersDuringLiveAnalysis>True</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzersDuringBuild>True</RunAnalyzersDuringBuild>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<Optimize>True</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Label="ConfigFiles">
<EditorConfigFile Condition=" '$(EditorConfigFile)' == '' ">$([MSBuild]::GetPathOfFileAbove('.editorconfig',
$(MSBuildProjectDirectory)))
</EditorConfigFile>
</PropertyGroup>

<ItemGroup Label="ConfigFiles">
<None Condition="Exists('$(EditorConfigFile)')" Include="$(EditorConfigFile)" Visible="false"/>
</ItemGroup>

</Project>
No description
Want results from more Discord servers?
Add your server