This question is about the difference between using /p:Platform=x64 on the MSBuild command line versus using <Platform>x64</Platform> in the csproj file.
I made two simple c# NET 5 solutions/projects with one executable (HsConsole) and one class library (HsLogger) to investigate when MSB3270 architecture mismatches occurred. Here is an example error message.
warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "HsLogger", "AMD64".
** Note the error message talks about MSIL (hsconsole) and AMD64 (hslogger), even though both the command line and project file specify x64 and NOT AMD64.
The HsLogger logger uses a post-build event to copy the class library to a folder that stores libraries for sharing among projects. The HsConsole project references the class library HsLogger from that folder.
The problem is that I get the MSB3270 error message (when compiling HsConsole) whenever I use /p:"Platform=x64" on the MSbuild command line, but not when I use no arguments on the command line. <Platform>x64</Platform> is already declared in the HsLogger project file in both cases.
Here are the two project files:
HsLogger
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Platform>x64</Platform>
<TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup>
</Project>
HsConsole
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Platform>AnyCPU</Platform>
<TargetFramework>net5.0-windows7.0</TargetFramework>
</PropertyGroup>
</Project>
Here is a summary of experimental results:
MSBuild hslogger.csproj /t:clean;restore;build -> compiles okay
MsBuild hsconsole.csproy /t:clean;restore;build -> no MSB3270 error
MSBuild hslogger.csproj /t:clean;restore;build /p:Platform=x64 -> compiles okay
MsBuild hsconsole.csproj /t:clean;restore;build -> gives MSB3270 error as shown above
** Note the error message talks about MSIL (hsconsole) versus AMD64 (hslogger).
Q1. Why is AMD64 in the error message when only x64 is used?
Q2. Why is an error message being produced at all when the command line and internal property both specify x64?