Visual Studio 2022 - MSBuild scenarios to Restore NuGet Packages with Custom Targets
I'm deploying to production and I'm having a hard time understanding I'm currently working on a .NET Core 3.1 application in Visual Studio 2022, and I've encountered an scenario where MSBuild fails to restore NuGet packages due to custom targets I've defined in my `.csproj` file... Specifically, I'm using a custom target to copy some files before the build process, but it seems to disrupt the package restore operation. When I run the build, I see the following behavior message: ``` behavior NU1102: Unable to find project information for 'MyProject'. ``` I’ve checked my `.csproj` file and the custom target is defined like this: ```xml <Target Name="CopyFilesBeforeBuild" BeforeTargets="Build"> <Copy SourceFiles="@(MySourceFiles)" DestinationFolder="$(OutputPath)" /> </Target> ``` The `@(MySourceFiles)` is a well-defined item group that I confirmed is not empty. However, it appears that when this target runs, it somehow causes MSBuild to lose context regarding the projects it needs to restore packages for. I've tried moving the target to different positions within the `<Project>` element and adjusting the `BeforeTargets` attribute, but nothing seems to resolve the scenario. I've also ensured that all necessary NuGet sources are configured correctly in the `NuGet.config` file. In addition, I have tried running `dotnet restore` from the command line and it works fine, so the question seems to be isolated to the Visual Studio environment. Is there a way to manipulate the build order or ensure that package restoration occurs correctly in conjunction with custom targets? Any insights would be greatly appreciated! This is for a REST API running on Ubuntu 20.04. Could this be a known issue? I'm coming from a different tech stack and learning C#. Has anyone dealt with something similar?