msbuild.net-8.0

Disable MSBuild auto-upgrade from <Reference> to a <ProjectReference>


I have a solution with two projects, where A references B through the dll.
From what I understand, MS Build replaces the Reference to a ProjectReference automatically.
Is there a way to disable this behaviour?

Giving a bit more context, the dll of project B has some classes which are not included in the project, but exist in the dll (a custom ms build ensures that), so ProjectReference wouldn't work.
Therefore, I'd like to continue having both projects in the same solution, but referencing the dll.


Solution

  • The question contains this statement:

    From what I understand, [MSBuild] replaces the Reference to a ProjectReference automatically.

    This is false. Just as the C# compiler doesn't change C# source files, solution and project files are input files to MSBuild and are never changed by MSBuild.

    Further, Reference and ProjectReference have different functionalities and ProjectReference is not an "upgrade" from Reference. An "auto upgrade" doesn't make sense.

    The Visual Studio IDE will change solution and project files. There is a UI for adding different types of references to a project. With .NET Framework there is an option for adding an assembly Reference. However, with a .NET project (.NET 8.0 as indicated in the question's tags) there is a ProjectReference option but no Reference option. A Reference can be added by directly editing the project.

    With a ProjectReference, the referenced project will be checked and built if it is out of date. A Reference just points to an assembly to be used. With both projects in one solution, set a build order in the solution file (not the projects) that ensures that project B is always built before project A.

    The question indicates that project B has custom MSBuild code. MSBuild files are XML files. It is possible, although a really terrible idea, for custom code in an MSBuild file to rewrite another project file. If project B is rewriting project A, that could be the source of the "auto upgrade". But it's not a feature of MSBuild.