NuGet.exe pack gives access to the path is denied - visual-studio

When I try to pack my MVC project (NuGet.exe pack) I get:
NuGet.exe : Access to the path '...' is denied.
This happens to be the case for all files in the content and script folder of my MVC solution. If I remove the readonly flag on all these files NuGet.exe is able to create the NuGet package.
Why do I have to remove the readonly flag? Is there another way?
I'm using TFS which specify the readonly flag on all files under source control.
I am running:
NuGet Version: 1.7.30402.9028
Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel
I'm using the NuGet.exe that you get when you install the NuGet package NuGet.CommandLine which is located at http://nuget.org/packages/NuGet.CommandLine.

Apparently, you need to set ReadOnly=false for the files it accesses

Try running it as administrator.

I ran into this with nuget restore after doing a git clean -fd with VisualStudio open: the packages/ directory was marked for deletion, and while several files were deleted, the packages/ folder itself was not as VisualStudio had the .nupkg files open.
Once I closed VisualStudio and re-ran git clean, it removed the packages/ directory and then nuget was able to restore everthing correctly.

In my case something happened when switching branch in git. Everyone lost execute permissions for Nuget.exe.
This blog post helped me: http://mannysiddiqui.wordpress.com/2013/05/11/nuget-access-is-denied-command-existed-with-code-5/

I was running into a similar problem. I attempted to restart Visual Studio, Run as Administrator (Which I always do), Set the folder attributes to ensure the 'Read-Only' flag was off. Regardless, whatever I did, I still encountered the error "access to the path is denied" when updating my Nu-Get packages.
I was able to fix the issue by updating packages one-by-one. Choosing instead to go through each dependency and updating it. Once the dependency was updated I would choose another, sometimes the same error resulted in which case I would choose another until all my packages were successfully updated.
It appears in my case the Nu-Get packages had to be updated in a particular order.
Hope this helps someone out there

I had this problem and it turned out windows had an update waiting for the next restart. Cleared with no problem after restarting and waiting for the update.

My collegue just got this error, during all "worked on my machine". After some research I found out that the *.nuspec file for some reason wasn't added to the version control.

In order to Restore nuget packages, remove read only permissions from the folder level (for windows). Clean the solution and Build. It will works

In my case it was *.gitattributes in the git repo root recently modified (incorrectly), so git started to checkout nuget.exe on the build server and converted all LF to CRLF inside, making it non-executable.

Run your Visual Studio with administrator rights.

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.

How to make my visual studio solution use the latest version of nuget.exe in teamcity

I have a .net website written some years ago which causes an error when being built in TeamCity. when teamcity gets to the second build step, MSBuild of the site's csproj file, i get this error when it tries to run package restore:
"The '…' package requires NuGet client version '2.12' or above, but the current NuGet version is '2.8.60318.667'"
The reason for this is that this solution includes the nuget.exe file in its directory which is of version 2.8.60318.667. Other projects/websites that i work on do not have the nuget.exe file in them and seem to be building in teamcity okay.
I need to either (1) update the solution so that i can remove the nuget.exe file, or (2) use the latest version, which should hopefully fix the teamcity issue.
When i replace my nuget.exe file with the latest from nuget i get an error message on build:
"1>D:\Sites\testSite.nuget\NuGet.targets(100,9): error : Could not find a part of the path 'D:\Sites\testSite\ \packages\System.Security.AccessControl.4.4.0'."
I think there is a space somewhere in a configuration file between the solution directory and the package location but i'm not sure where to look. Can anyone help?
I have tried deleting the .nuget folder from my solution but i get errors when i build. Can anyone help me reconfigure my solution to work without the specific, local version of nuget?
If anyone can help in any way i'd really appreciate it, i'm reaching the limit of my understanding of visual studio and .net.
thanks
Sam
You can install multiple versions of Nuget tool in TeamCity and set any one as default
i.e v4.4 as default.
For this follow the TeamCity doc link : TeamCity Doc
Now for specific build step if you want to use lower version of nuget you can choose different version of nuget installer/restore as shown in attached image
The issue I had when replacing the nuget.exe file was due to the version of the file I downloaded. I took an older version (4.6.4) and I did not get the issue with the space in the path to the packages when building the solution.
There were other errors but i have resolved them now.

error Build: File 'COMPUTE_PATHS_ONLY.ts' not found in visual studio

I received the following error after the repair of visual studio 2015.
Error Build: File 'COMPUTE_PATHS_ONLY.ts' not found.
COMPUTE_PATHS_ONLY.ts is not from my Git repo. Other files in the Git repo have not changed. What could it be?
I found answer here, it works for me: https://github.com/Microsoft/TypeScript/issues/7445
the error indicates that there is a mismatch between your targets (C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets) and the tasks dll (C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\TypeScript.Tasks.dll); this would be an issue with the installer not handling a specific order of installing different versions.
Can please try:
uninstall TS 1.8.* from Add/Remove Programs
uninstall TS 1.7.* from Add/Remove Programs
make sure the folder C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript is empty, if not remove it manually
install TS 1.7.6 again, you should see the folder created in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript
For me the solution was to move the folder at
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\TypeScript
to
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript
and overwrite everything there.
This answer helped me a lot, I could solve my problem this way
When I removed "COMPUTE_PATHS_ONLY" from the
line Configurations="$(TypeScriptBuildConfigurations)
COMPUTE_PATHS_ONLY" in the file Microsoft.TypeScript.targets, my
problem was solved.
The steps mentioned above will not guarantee to fix your issue. After following the steps mentioned above I was keep getting the same compiler error.
I restarted my machine after "uninstall and install" operation but no luck.
Finally, I found that instead of doing all these from control panel we have to do it from package manager (Right Click on solution and select "Manage Nuget packages for solution.."
First uninstall the TS package for your project from package manager and then install the package and build.
Img of project setting
I was using the VS 2015 update_1 and type script version 1.8
For me it was solved by updating VS 2015 in update_3
https://msdn.microsoft.com/en-us/library/mt752379.aspx

MSBuild fails due to invalid NuGet version on build server

I updated to VS2015 this week and along with that updated all NuGet packages in my website solution.
The site builds and run fine locally, however when doing my gated check in to my build server, I get the following when the build fails
As you can see the packages are complaining about the NuGet version, but I'm unsure how to update the NuGet version on the build server. I do have admin privileges to the server, but following the guild described at: http://blog.stangroome.com/2014/02/04/update-nuget-exe-version-used-by-team-build-2013-package-restore/ did not help. For one, my folder was actually C:\Program Files\Microsoft Team Foundation Server 11.0\Tools unlike the C:\Program Files\Microsoft Team Foundation Server 12.0\Tools described in the guide, but additionally I did not have a NuGet.exe within the folder.
I've done a full hard drive search of NuGet.exe, but could not locate it in any directories aside from the directories that are directly related to project source code (.nuget\NuGet.exe).
I have opened visual studio on the server and updated the NuGet version within "Extension and Updates" hoping that would fix the issue, unfortunately it did not.
Any ideas on how to fix the issue/errors presented in the screenshot?
The problem is that you're using the old-style, deprecated-since-NuGet 2.7-style "package restore" that's based on modifying your CSProj files to include references to a NuGet.targets file and a copy of NuGet.exe that gets put into a .nuget folder and ends up source controlled.
Basically, the version of nuget.exe that's on the build server is irrelevant right now -- your CSProj files are pointing to the file in your .nuget folder.
TFS 2013 and beyond has support for automatic package restore without using the NuGet.targets method. You can migrate off of it pretty easily: https://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

TeamCity Missing Items in Work Directory Checkouts

I've been pouring over my set up for what feels like most of the day and I cannot figure out what I'm doing wrong.
I have 3 build configurations running on a single agent on my dev box. Checking out code from SVN.
I've got OctPack installed to create a couple of packages for deployment. In addition to this I've created a nuspec file to use in a NuGet Pack step. All of these bits work fine when testing.
The problem is that the nuspec file packages up some sql script files for deployment. Nothing fancy.
The problem is these sql files are disappearing from disk in the work folder. I get:
Cannot start build runner: Failed to find files to create packages matching: [src\database\SqlScriptsPackage.nuspec] under H:\TeamCity-Build\work\a1dbf81458fbab0a.
The entire database directory is empty despite all the contents being in SVN.
I've tried everything I can think of, including a forcing a clean checkout.
All the projects are using the same VCS Root setup to checkout "Automatically on server".
What could be ditching all these files?
Disable the [] Clean output directory checkbox on the NuGet Pack step.
I had this issue where I set the target directory for the Nuget pack step to be the same folder as the .csproj file I was building from.
With the tickbox ticked, it wiped the entire directory immediatly after checking it out.
I had a similar error when running on TeamCity:
Failed to find files to create packages matching: [myProject/myProject.nuspec]
under {C:\TeamCity\work\XXXXXXXXXX}
The key for us was that reading this message you could interpret it as it cannot find the files to go in the nuget package.
However, the issue was that it cannot find the .nuspec file.
So this then helped us look at the TeamCity working directory and what we were missing to get to the 'myProject' .nuspec path above.
Another thing to check is that you have the Octopack nuget package installed in your Visual Studio project. I forgot to do this with one of my projects and received the "Failed to find files to create packages matching" error. More information is available here:
http://help.octopusdeploy.com/discussions/questions/2304-teamcity-804-not-creating-nuget-packages

Resources