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:
<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;
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.