how generate project.assets.json - visual-studio

I create a new .NET Standard project and try to build without any code added, I get
"Assets file 'E:\Storage\Google Drive\My Content\My Documents\My LC
TECH\Projects\LC Development\LC.Assets\obj\project.assets.json' not
found. Run a NuGet package restore to generate this file."
I've tried to run dotnet restore but without luck.
How to create the file or remove reference to it?
I use Visual Studio 2019 preview, but had same error when using Visual Studio 2017.

turned out that this was caused by an faulty installation of .net core sdk.
installed everything again and it started working

Related

Assets file project.assets.json doesn't have a target for 'net6.0' - VS2022

Just a few days ago got this error, after updating to Visual Studio Community 2022 v17.2 (from v17.1.6):
Error NETSDK1005
Assets file 'C:.........XXXXXX.Web\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project. XXXXXX.Web C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 267
Uninstalled everything related with VS2022 + Installer
Rebooted
Fresh Git Cloned the project I'm working on (I work on several computers all with Win 10 and all with the latest updates, this is the only VS installation that presents this problem)
Reinstalled VS 2022 v17.2 (with .NET 6.0, the usual install)
The .csproj file has everything in place:
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);(SpaRoot)\**\node_modules\**;</DefaultItemExcludes>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
Always delete the 'bin' and 'obj' folders before build or rebuild....
Cannot get away with the compilation, and always receiving that NETSDK1005 error...
Getting desperate :(
Thanks in advance for any help
P.S. - already checked question 70711153
I found the problem and it indeed had to do with restoring NuGet Packages, in that I have a connection to a corporate NuGet repository, and the call to it was breaking due to wrong credentials.
What was troubling was that the error did not identify the nature of problem with the connection or the username of the credentials getting refused.
On the logged in user popup dialog window, where the several used usernames are presented, there was one username that was required to re-enter its password.
That was all it took.
Visual Studio > Tools > Options > Azure Service Authentication. ReBuild and the NuGet Packages will be restored and build successful.
We had this issue in our Azure DevOps pipeline and it ended up being that the "NuGet Restore" task was using an old version of NuGet. You can see which version the pipeline is using if you check the logs for the "NuGet Restore" task and look for the "Detected NuGet" line.
We:
added in the "NuGet Tool Installer" task before the "NuGet Restore" task
Under the "Version of NuGet.exe to install", list the version you want to use, or the minimum version (e.g. >=6.1.0)
(this step is possibly overkill) Under the "NuGet Restore" Task, check "Disable local cache"
This happens because NuGet writes a file named project.assets.json in the obj\ folder & the .NET SDK uses it to get information about packages to pass into the compiler. In .NET 5, Nuget added a new field called TargetFrameworkAlias, and thus in MSBuild versions < 16.8 or NuGet versions < 5.8, it is possible that you can generate an assets file without the TargetFrameworkAlias as it will read the property and not find it.
You can resolve this issue by ensuring you are on MSBuild version 16.8+ & using NuGet version 5.8+.
In my case I have commented out the TargetAlias line and it published successfully.
Reference: https://developercommunity.visualstudio.com/t/error-netsdk1005-assets-file-projectassetsjson-doe/1248649
For me, I was getting this when updating my projects from .NET Core 3.1 to .NET 6. I had my .NET 6 code in another Git branch and when I switched from the main 3.1 branch to the 6 branch and then tried to build the solution, I would get that message.
After some trial and error, the solution that worked for me was doing the Git checkout and the restore via command line.
Close the solution
From the Developer Powershell (or using regular Powershell or the Visual Studio 2022 Command Prompt), navigate to the local directory that has your repo, and then:
git checkout [branch name]
dotnet restore
Then back in Visual Studio, reopen the solution and build, which would work.
For me, this happened after switching from .net6.0 to .net 7.0 in asp.net core / blazor project. The error occured when trying to publish the project to IIS.
Solution was to switch the "target framework" in the publishing configuration (.pubxml) in the "Publish"-tab.
For me this fix worked:
If you don't have the dotnet cmd line tool, download and install the .NET 6 SDK.
Open a cmd prompt and run the command:
dotnet restore <path to your solution>
(for instance: dotnet restore c:\app\myapp.sln)
nuget restore resolved the same issue
and/or dotnet restore
I had this bug in a solution with several SDK plus non-SDK C# projects.
What fixed my case:
Close the solution.
Separately open the first project of the solution that Visual Studio failed to build.
Build the project. --> "Error not found and build is OK"
Reopen solution. --> "Error disappeared"
I got the same error when publishing Web API to the cloud.
Use Tools ->Command line -> Developer command prompt in Visual Studio 2022, enter AZ login, and after login, restart the visual studio, it is working for me again.
Had the same problem in Azure Devops, using a Windows 2019 build server with VisualStudio 2022
Error:
##[error]C:\Program Files\dotnet\sdk\6.0.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): Error NETSDK1005: Assets file 'C:\agent\vso_work\4\s<..>.API\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project.
Resolved by adding a "NuGet Tool Installer" using version >=6.0.0
Before the NuGet restore task
enter image description here
we got this problem when added cache on gitlab, and started to use dotnet restore,
it happend because we missed the "runtime" parameter to the restore command,
- dotnet restore --packages .nuget --runtime win-x64
- dotnet publish --no-restore --runtime win-x64
In my case the problem was I had updated the Nuget package version in one assembly but not in another, so check you have the same nuget package versions across your solution.
For me, it works to set the target framework to another framework like .NET Core 3.1, build the application, set the framework to the original framework and rebuild.
In my case I had inadvertently added a couple of projects to the solution that were in another folder. I received no errors until I changed NET version from NET6.0 to NET6.0-windows on one of the projects. The solution then didn't build, with 100s of errors, but each individual project built OK.
I noticed that "project.assets.json' doesn't have a target" error among all the errors, pointing to the outside folder.
Bringing those projects into the solution folder fixed the error.
I got the same error sometime back. This worked for me: Logout from visual studio and login to visual studio account
I had an error:
Ensure that restore has run and that you have included 'net6.0' in the
TargetFrameworks for your project. You may also need to include
'win10-x64' in your project's RuntimeIdentifiers.
I removed bin and obj folders for this project and rebuilt the project. dotnet clean, dotnet restore didn't work for me.
I had the same problem ("...\obj\project.assets.json' doesn't have a target for 'net6.0'. Ensure that restore...") with clean batch compilation of my sln: msbuild 17.4, nuget 4.7.
I replaced string
nuget.exe restore my.sln
with string
msbuild.exe my.sln /t:Restore
that was before
msbuild.exe my.sln /t:Build
and everything worked.
I got the same error this morning.
This worked for me: right click on solution explorer in visual studio -> 'Restore NuGet Packages'.
Hope this helps.

Flutter windows build: Nuget is not installed

I uninstalled Visual Studio 2019 and installed it as 2022.
I reinstalled Flutter.
When building Flutter desktop, the following problem is repeated.
If I run it in another project, it works without any problem.
Launching lib\main.dart on Windows in debug mode...
Building Windows application...
Nuget is not installed.
Nuget.exe not found, trying to download or use cached version.
1- make sure you have installed Visual Studio
2-
NuGet Package Manager (PM UI and PM Console) is included with Visual
Studio. The latest NuGet releases are delivered as part of Visual
Studio updates.
HOWEVER: nuget.exe itself is not included with any version of Visual Studio.
so you need to download the latest NuGet Windows x86 Commandline from https://www.nuget.org/downloads
3- put it inside the flutter sdk folder or any folder you like
4- copy the folder path
5- in windows serach, search for env so you can put it as system variables. edit path with a new line and past the folder path
6- restart android studio
7- congrats
there's a video on youtube for the exact steps:
https://www.youtube.com/watch?v=J5b5sj6mG8M
Although I don't know why it would work without this error message on the same machine, I recently ran into this issue as well. The way I fixed it was to download the nuget executable and add it to my path.

aspnetboilerplate core brand new project does not build in vs 2017

I have downloaded asp.net core 2.x angular js template. Opened up with vs 2017 version 15.4.1 and it does not build. When I try to build or restore nuget packages it throws up below error.
The error message :
Severity Code Description Project File Line Suppression State
Error Assets file '...\3.3.2\aspnet-core\src\MyNg2Project.Core\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. MyNg2Project.Core C:\Program Files\dotnet\sdk\2.0.2\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets
Thanks in advance.
It turned out I had specified local nuget package source to update or restore packages with my team in earlier version of visual studio. Visual studio 2017 assumed that this local path still exist and prioritized it. When I uncheck the old path from the main source of nuget package it worked like a charm.

VS2017 Metadata file '.dll' could not be found

After upgrading to Visual Studio 2017, I am unable to build my project. Visual Studio 2015 still works when pointing at the exact same project.
this is the build errors I get Metadata file '******.dll' could not be found
I've already tried https://stackoverflow.com/a/17723774/3511012 with no success
I tracked the issue down to a specific NuGet package that has not yet been updated for visual studio 2017. (Baseclass.Contrib)
It isn't yet registered as having updates available through the nuget package manager, but you can manually update using the nuget console and running this command Install-Package Baseclass.Contrib.Nuget.Output -Version 2.3.0-vs20172

error MSB4019: Microsoft.WebApplication.targets" was not found

I created a project using Visual Studio 2010 and trying to create the build in TFS 2013. I am getting the following error. Target Framework is 4.0. Why my build server is looking for Visual Studio 12.0 folder? How to change this settings? I appreciate any suggestions.
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" was not found
Copy the directory "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0" from development machine to the build machine.
http://howtoscript.blogspot.com.tr/2014/05/error-msb4019-imported-project-cprogram.html?view=magazine
You need to do one of the following:
Change the build configuration to use 2010
Install VS 2013 on the build server.
I would recommend upgrading your visual studio anyway as you are already 2 versions behind with CTP's already available for DEV14,..

Resources