An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Thank you or reaching out.
This happens because in Release your MyProject.ConsoleApp is built as a self‑contained executable (<SelfContained>true</SelfContained>), while MyProject.TestApp is not self‑contained. When one executable project references another executable project, the .NET SDK requires that both projects match on the self‑contained setting (either both true or both false). If they don’t match, the SDK raises NETSDK1151 to prevent producing an output that may not run correctly.
In Debug, you don’t set SelfContained=true, so there is no mismatch and the solution builds without issues.
To fix this while still meeting your requirements (publishing the ConsoleApp as self‑contained and running integration tests), you have a few options:
Recommended approach:
Avoid referencing the Console EXE directly from the test project. Instead, move the code you want to test into a class library (for example, your existing MyProject.Lib) and reference that library from both MyProject.ConsoleApp and MyProject.TestApp. This avoids the “exe referencing exe” restriction completely and matches the typical design described in the .NET documentation, where applications reference libraries rather than other executables.
Keep the project reference, but match settings: If you need to keep the project reference from MyProject.TestApp to MyProject.ConsoleApp, then make the test project self‑contained as well, so both projects match. This removes the error because the SDK check is specifically about mismatched self‑contained values. The trade‑off is that your tests become more platform and runtime specific.
Make self‑contained only during publish : Keep your normal Release build (used by tests) as framework‑dependent, and apply SelfContained=true only when you publish (for example, using a publish profile or dotnet publish). Publishing is the supported step for producing deployment output. With this approach, tests can build and run in Release without hitting the mismatch, and you still get a self‑contained ConsoleApp when you publish.
Workaround: If you understand the implications and simply want to bypass the check, you can disable the validation by setting: <ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained> Microsoft documents this as a way to avoid the error, but the trade‑off is that you are opting out of a safety check. This check exists because mixing self‑contained and non‑self‑contained executables can lead to outputs that are not runnable as expected.
Reference: explanation of NETSDK1151 and the recommended actions:
Breaking change: Error generated when executable references executable
Please let us know if you require any further assistance, we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer". So that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.