8

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?

Bent Tranberg
  • 3,445
  • 26
  • 35
  • 2
    That error has been around for as long as I've been using F#; probably as long as F# itself. It has something to do with the F# MSBuild targets not being properly imported. I recently had the issue on one machine and "fixed" it by adding the `` part starting at https://github.com/TeaDrivenDev/FilenameEmbeddedMetadataOrganizer/blob/6dfe67116deec6199db42b36c4bbc0f441dc3769/FilenameEmbeddedMetadataOrganizer/FilenameEmbeddedMetadataOrganizer.fsproj#L44 to the project file. After the next Visual Studio update, the issue was gone, and it worked without the above "fix". – TeaDrivenDev Jul 06 '18 at 22:34

2 Answers2

3

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.

Bent Tranberg
  • 3,445
  • 26
  • 35
  • Since I reported this, I have added several F# and C# Standard 2.0 libraries and one F# Core 2.1 Console application to this solution. I didn't need to add this command for each of these other libraries in order for the build to go through, even though they contain nuget libraries that the first lowest level library isn't using. I don't know why this is, and won't bother to investigate. – Bent Tranberg Jul 13 '18 at 06:36
  • Later I added even more projects, and some of them do require a donet restore. So now I've made sure every Standard and Core project gets a dotnet restore in the build script, to avoid breaking at some seemingly arbitrary point. At some point I'll be rid of Framework, and then I expect I can simply just do dotnet restore on the entire solution. – Bent Tranberg Sep 20 '18 at 18:43
  • Later I discovered that being able to do dotnet restore doesn't depend on the project being Core/Standard and not Framework, but rather on the project file having the new format. So now I still have one Framework project in the solution, but it has been converted to the new project format. That makes it possible to do dotnet restore on the solution, which is ideal for my build script. – Bent Tranberg Dec 18 '19 at 11:38
2

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)')"
Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
Bulat
  • 21
  • 2