Build pulling in wrong framework version from ProjectReference

I have a solution which contains several projects. One of these (call it ProjectA) is set to build for <TargetFrameworks>net48;net6.0</TargetFrameworks>. There are a couple of other projects which are only .NET 4.8 and reference ProjectA and they build fine, but the unit test project gets an odd compile error when built via MSBuild on our Jenkins build agent (VS2022 builds just fine)

Assembly ‘ProjectA’ with identity ‘ProjectA, Version=24.3.99.0, Culture=neutral, PublicKeyToken=null’ uses ‘System.Xml.ReaderWriter, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ which has a higher version than referenced assembly ‘System.Xml.ReaderWriter’ with identity ‘System.Xml.ReaderWriter, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

Assembly ‘ProjectA’ with identity ‘ProjectA, Version=24.3.99.0, Culture=neutral, PublicKeyToken=null’ uses ‘System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ which has a higher version than referenced assembly ‘System.Runtime’ with identity ‘System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’

It seems like it’s pulling in the .NET 6 version instead of the .NET 4.8 version. To confirm that, if I change ProjectA to only build as .net 4.8, the unit test project builds just fine.

After some Googling, I tried including it this way:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><ItemGroup>
<ProjectReference Include="....srcProjectAProjectA.csproj" >
<SetTargetFramework>TargetFramework=net48</SetTargetFramework>
</ProjectReference>
</ItemGroup>
</code>
<code><ItemGroup> <ProjectReference Include="....srcProjectAProjectA.csproj" > <SetTargetFramework>TargetFramework=net48</SetTargetFramework> </ProjectReference> </ItemGroup> </code>
<ItemGroup>
    <ProjectReference Include="....srcProjectAProjectA.csproj" >
        <SetTargetFramework>TargetFramework=net48</SetTargetFramework>
    </ProjectReference>
</ItemGroup>

But that didn’t help.

I’ve also tried building the unit test project as both 4.8 and 6 (that’s the goal anyway) and it gets the same error.

One thing that may be a clue is that it works fine if I build it using Visual Studio 2022, but the Jenkins build using MSBuild gives the error. I’m not sure what version of tools are installed on the Jenkins build agents. I’ve asked but not gotten

I don’t know if it’s relevant, but the unit test project pulls in these Nuget packages

  • Moq 4.18.4
  • NUnit 4.1.0
  • NUnit3TestAdapter 4.5.0
  • Should 1.1.20

There’s another error which I assume is related

error CS0119: ‘Extensions.Attributes(IEnumerable)’ is a method, which is not valid in the given context

Which is odd because the code in question is doing something like;

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>var value = node.Attributs["Key"];
</code>
<code>var value = node.Attributs["Key"]; </code>
var value = node.Attributs["Key"];

Where node is an XmlNode and Attributes is a property of type XmlAttributeCollection. Again, VS2022 compiles just fine, but MSBuild is confused.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật