The target "MyProject:Restore" does not exist in the project.

About half of my projects give this when attempting to publish them. They won't even try to build because I guess they don't even get to the restore step.

The build output is this:

CONSOLE: Use build tool: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe
Target ValidateSolutionConfiguration:
Building solution configuration "Debug|x86".
Target ValidateProjects:
The project "SomeOtherProject" is not selected for building in solution configuration "Debug|x86".
-1>C:\Path\MySolution.sln.metaproj: Error MSB4057 : The target "Folder1\Folder2\SomeProject:Restore" does not exist in the project.
Restore failed at 2:09:53 PM 

This is a .NET Core 3.1 application.

My publish configuration looks like:

Target Location: <network folder path>
Configuration: Release | x86
Target framework: netcoreapp3.1
Deployment mode: Self-Contained
Target runtime: win-x86 (also have tried Portable)
Enable ReadyToRun compilation: false
Trim unused assemblies: false
Produce single file: false
Delete existing files: true

Using identical settings I am able to publish the same project from VS2019. There is also no problem building, running, or nuget restoring in general; this problem only occurs on publish. I am also able to publish an ASP.NET Core 3.1 web application that uses the same libraries without issues. It seems to be publishing .NET Core 3.1 desktop applications that has issues.

Also, note that the project name in the error message is not the project I'm trying to build. I'm not even sure it's necessarily one of its dependencies. It seems to just be an arbitrary project from the solution, somewhere close to the top of the dependency hierarchy; I presume it is just the first project in the list of projects to be restored.

Comment actions Permalink

Hello Dave, 

Could you please send your *.sln and *.csproj files, and also logs collected right after the issue is reproduced via Help | Collect Logs? Please upload all the information along with a new issue on our tracker. Thank you in advance!

Comment actions Permalink

I guess I want to avoid sharing details of my codebase.

I tried making a new solution but couldn't get the problem to occur.

I tried copying my solution file to a new folder and opening it, and found that the problem went away (still can't publish, but not instant failure with "target does not exist"; instead much more meaningful results.)

I tried renaming the .idea folder to .idea_old (and some other Rider and nuget related files) in my real solution folder, and this had the same effect.

Without the instant failure I feel like I can probably work through the errors now (mostly "detected package downgrade"). (And indeed I have.)

Comment actions Permalink

K it came back and I think I know why. I suspected this but wasn't sure, but now I have a pretty simple repeatable example:

 - Create a blank solution

 - Add a project: .NET Core 3.1 Windows Forms Application

 - (don't call the application "Application" which I did in testing, since that is the name of a Windows Forms class)

 - Add a project: .NET Core 3.1 Class Library

 - Unload the Class Library project

 - Attempt to publish the Application to a local folder, but set its Target runtime to "win-x86"

You should get the error "The target "WindowsFormsApplication:Restore" does not exist in the project."

Note that there is no reference to the library needed.

You should find that if you reload the class library, that the problem goes away, and comes back if you again unload it.

The problem still occurs for the target runtime of "win-x64". The problem does not (always) occur if target runtime is "Portable", although that is not an option in the drop down box (though it was the default I think).



Please sign in to leave a comment.