执行dotnet ef迁移时触发MSB1006错误的排查与解决
If you're hitting the MSBUILD : error MSB1006: Property is not valid error while trying to run Entity Framework Core migration commands, here's the breakdown of the issue and how to fix it.
The Problem Scenario
When executing commands like:
dotnet ef migrations add
or
dotnet ef migrations script
you'll get a confusing error message that looks like this:
MSBUILD : error MSB1006: Property is not valid. Switch: \tmpBCE7.tmp For switch syntax, type "MSBuild /help" Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
At first glance, this makes it seem like there's an issue with your project configuration or MSBuild setup—but the actual root cause is much simpler.
The Solution
I stumbled on the fix while checking environment variables for an unrelated task: the problem was an extra semicolon at the end of the TMP user environment variable.
Here's how to resolve it:
- Open your system's environment variables settings (on Windows, go to Control Panel > System > Advanced System Settings > Environment Variables)
- Under the "User variables" section, locate the
TMPvariable - Edit its value to remove the trailing semicolon
- Save the changes, then restart your terminal or IDE to apply the updated environment variable
Once you've done this, re-run your EF migration commands—they should execute without triggering the MSB1006 error.
内容的提问来源于stack exchange,提问作者BDarley

