简体   繁体   中英

MSB4020: The value “” of the “Project” attribute in element <Import> is invalid

I have a solution with .NET Framework projects in mostly F# and then a few in C#. I use Paket instead of NuGet for packet management. Now I've added my first .NET Standard 2.0 library to this solution.

When I run my build script, which runs another build script, which calls devenv to compile, there is an error that says the project's obj\\project.assets.json file is missing. It is actually generated while compiling, but only if one of the other projects are compiled. Why then it is reported as missing is a little bit weird.

If I run just the inner script, there's no problem. If I open VS and compile, there's no problem. Funny.

I'm not quite sure how stuff works - or not. But after googling it seems this file should be put there before compiling with devenv (Visual Studio), and not put there by devenv.

I ran Paket restore. That didn't produce the missing project.assets.json.

I googled my way to "dotnet restore". When running this, I get this error on several of the older projects.

MSB4020: The value "" of the "Project" attribute in element <Import> is invalid.

So the question is, what do I do now?

I finally figured out that after the Paket restore, I could run this command on only the new .NET Core project, thereby avoiding the errors from the other projects in the solution.

dotnet restore TheProject

Then the missing file was generated before compile, and the rest of the build script ran to completion.

PS (edit): This is not a perfect solution for me, because I have to add that line to my build script for every .NET Standard and .NET Core project in my solution. Having to maintain the script like that is not ideal. For that reason I will look into what has to be done to get rid of the MSB4020 error. Until then, this serves as a good workaround.

I can advise you to try changing the project file (.fsproj) as follows:

  1. Open the project file and find the line: Import Project="$(FSharpTargetsPath)"
  2. Add: Condition="Exists('$(FSharpTargetsPath)')"
  3. As a result, you should get the string : Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM