unable to locate nuget.exe when building webservice on appharbor - appharbor

I'm trying to deploy my webservice at appharbor using codeplex.
After trying it the first time and doing some research I found out that I had to use NuGet so the references are being found..
Now I only have 1 error left which I don't know how to solve
"D:\temp\g3wyilvx.uln\input\WebService\Webservice.sln" (default target) (1) ->
"D:\temp\g3wyilvx.uln\input\WebService\Webservice\Webservice.csproj" (default target) (2) ->
(CheckPrerequisites target) ->
D:\temp\g3wyilvx.uln\input\WebService\.nuget\nuget.targets(72,9): error : Unable to locate 'D:\temp\g3wyilvx.uln\input\WebService\.nuget\nuget.exe' [D:\temp\g3wyilvx.uln\input\WebService\Webservice\Webservice.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.17
How am I suppose to solve this error ?
Any useful links that might help me in the future are also appreciated.

I solved this by changing this line in my NuGet.targets file and setting it to true:
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
But you must restart Visual Studio or reload the solution (see this) for this to take effect.

I resolved the problem by right clicking Solution and click
Enable NuGet Package Restore

Executables might be ignored in your .gitignore via
*.exe
Add this line to .gitignore:
!.nuget/NuGet.exe

Enable NuGet Package Restore
Right click on solution then
select Enable NuGet Package Restore

Here's a blogpost on using NuGet package restore with AppHarbor. In your case, the problem might be that you haven't included the .nuget folder in your repository.

I faced this issue, when one of my colleague added a new project in solution. He added new packages from nuget. The above top rated answer was not acceptable for me because once I update nuget packages, it updates all referenced libraries in the project.
How I removed this error, by just removing import statements for nuget package from .csproj files.
To do so, right click on .csproj file, and open it in notepad and remove the statement.

Related

Cannot restore nuget packages on VSTS (Packages failed to install)

I'm using Visual Studio Team Services to build a .NET solution. I have a Nuget Installer task to restore the packages of the solution that is configured as follows:
Nuget.config file has 2 package sources - one is nuget.org (v2) and the other is a custom feed (Nuget Server v2.5.40416.9020). All packages from the nuget.org feed are restored but the ones from the custom feed are not, for each package from the custom feed there is an error message like this:
Unable to find version 'abc' of package 'xyz'
Error:
[error]Error:
C:\a_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.22\node_modules\nuget-task-common\NuGet\3.3.0\NuGet.exe
failed with return code: 1 [error]Packages failed to install
This was working fine 1 or 2 days ago.
Locally everything seems to work fine. Also, I tried with the nuget version 3.5.0 and a custom version of nuget.exe, without success.
Any suggestions?
I just had this error today. I fixed this error by reviewing the changes in my solution file with our base code branch and found some old lines that weren't supposed to be there. I think they were a result of a bad merge and should have been removed during a conflict resolve.
To fix the issue I simply removed the references that were old and everything built just fine.
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{EAECFF2D-7339-4180-8E1E-6DF9EC9EB131}"
EndProject
{3C14F190-6B6A-4913-9681-AFD9B62850FA} = {EAECFF2D-7339-4180-8E1E-6DF9EC9EB131}
{687ECE00-A567-40F3-BFF9-C3B639328F27} = {EAECFF2D-7339-4180-8E1E-6DF9EC9EB131}
Thanks,
Fissh

How can I fix missing nuget references after moving project in Visual Studio 2015

I had a project structure like this:
WebApp
-- WebApp
-- WebApp.sln
WebApp.Tests
-- WebApp.Tests.csproj
I moved WebApp.Tests into WebApp using a move (simple click & drag into the WebApp folder). I edited WebApp.sln to fix the project reference so that it will load.
When I build, Nuget complains that packages are missing and to do a restore.
I downloaded and used nuget.exe restore on my solution and it reported everything was there.
Based on other Stack Overflow answers, I have tried the following:
Edit the test project reference hint paths. I changed from ..\WebApp\packages\PACKAGE to ..\packages\PACKAGE
Reload Visual Studio (multiple times)
Delete contents of packages folder and bin/obj folders of the projects
Use the package manager console to reinstall packages on the Test Project
All of these failed to fix the problem. When I used the package manager to try to reinstall the packages with the command, it gave me the same error that project building does - I must restore the packages first.
Is there any quick way to fix my project? I really don't want to go through each package and uninstall/reinstall manually. Also, how could I have prevented this problem in the first place? Is there a built-in way to move project locations?
There was XML similar to this at the end of my project file:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\WebApp\packages\SPECIFICPACKAGE')" Text="$([System.String]::Format('$(ErrorText)', '..\WebApp\packages\SPECIFICPACKAGE'))" />
</Target>
By changing the ..\Webapp\packages to ..\packages like the rest of the file, my solution compiles just fine now.
I had the same issue where I physically moved a project folder into the src folder and got the missing packages error. My fix was to open up the .csproj file in notepad and replace every instance of
this:
..\packages\
with this:
..\..\packages\
It solved the issue...

How do I set Visual Studio to build a NuGet package?

How can I get Visual Studio to build a NuGet package for my library component on build?
I’m using a Portable Class Library as the example project.
Ensure the NuGet.exe file in .nuget folder is latest.
Default values come from AssemblyInfo.cs, so clean that up.
Add a NuGet package reference if you do not reference any, preferably something simple like JSON.NET. Often, PCL projects have no external dependencies, in which case no NuGet refs and without any NuGet refs, the required MSBuild config won't get set properly, so we need to add a 'dummy'.
Enable NuGet Package Restore.
Edit the NuGet.targets file and ensure BuildPackage is true.
<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">true</BuildPackage>
Edit your .csproj file and add this to the first, default PropertyGroup
<BuildPackage>true</BuildPackage>
Rebuild your project and then search in the Output for nupkg and confirm creation and location of the package file.
Remove the dummy NuGet package reference and build again and check the Output.
To further customize the package creation, you can stick a MyProjectName.nuspec file next to your .csproj file.
See http://docs.nuget.org/docs/reference/nuspec-reference for more on the NuSpec format. You can also pull one from an existing package (its just a zip file) and have a nose around, see how it was done.
Add a post-build event like this:
$(SolutionDir)\.nuget\nuget.exe pack "$(MSBuildProjectFullPath)" -p Configuration=Release -o "$(MSBuildProjectDirectory)\bin\Release" -symbols"
And download and place nuget.exe in the .nuget folder alongside your solution file.
You can use nuget update -self to keep the .exe fresh.
Note
nuget.exe pack has a bug currently where it'll see a packages.config file and try to look for the packages it mentions in your solution but it fails to find them if the packages folder is in a strange place, e.g. if your solution file isn't a level up from the project.
To workaround this, add another post build event to copy the packages folder into the project folder.
The repositorypath config setting seems to do nothing for me.
See GitHub reports:
https://github.com/NuGet/Home/issues/5316
So funny. I was having problems with my usual way of auto-building a package on build when I arrived at this new way. So I looked for a suitable SO question to answer with my new post-build method when I came across my own question here!

Prevent NuGet Restore Package in debug builds only

I enabled the Restore Package option in my solution so when I upload the code to the CI server it updates all the packages that it needs to build correctly, and it works great. Now the problem is that on my local machine, the build takes a long time to start because is "updating the packages". Is there a way to enable the Restore Package in release build only?
I've tried to move the <RestorePackage> property in the .csproj files to the release/debug sections with false and true, but NuGet updates the attribute when a open the NuGet console and resets both to true; also tried to only include the property in the release section, but then NuGet adds it to the global section... so I had no luck making it stay the way I want it...
Any advice?
You have probably managed to answer this by now but if not then these are the steps you need to follow
Right where your solution file is within Windows there should be a folder named .nuget. Either rename or delete this folder.
Now open each .csproj or .vbproj file in notepad or any text editor and remove these lines
<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />
The important part is removing/renaming the .nuget folder. This should now disable package restore completely.
Edit: To selectively disable package restore for DEBUG builds edit the Nuget.settings.targets file and modify the following line
<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>
To
<RestorePackages Condition="$(RestorePackages) == '' AND '$(Configuration)' == 'Debug'">false</RestorePackages>
The Nuget.settings.targets file is under the .nuget folder which should be in the same folder as your solution file.

remove nuget package restore from solution

I added the recent nuget package restore feature to a solution using 'Enable NuGet Package Restore':
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
However it broke my build server and I didn't have the time to fix it, so I wanted to remove it. There's no option for that as far as I know, so I removed the following line manually from all my *.csproj files:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
The problem now is that every time my *.csproj files are checked out or open my solution, the line is automatically added again, breaking my build if I accidentally check it in :(
Any ideas how I can remove it permanently?
UPDATE: despite the answer below it still keeps coming back when opening the solution, anyone with the same problem?
I didn't look very well, there's another property added to the project files:
<RestorePackages>true</RestorePackages>
Just have to remove this as well as all these lines manually from all *.csproj files:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
UPDATE:
Turns out it's a persistent little bugger, if you're manually editing your project files, make sure to close the solution and delete all the lines from the project at once, otherwise they're just added again once the project reloads...
UPDATE2:
Delete the .nuget folder from the solution root too
UPDATE3:
A later version of NuGet adds another section that you need to remove:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
Update4
Inside the NuGet.Targets located in the .nuget folder, there is another section that gets added to new projects... switch it to false.
<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'false'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>
To disable Nuget Package Restore:
Delete .nuget folder
Remove specific lines from all .csproj files
Lines to remove:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<RestorePackages>true</RestorePackages>
Note: Make sure you do all changes in one go before reloading solution or else it will add them back.
This is based on the following article:
http://bartwullems.blogspot.no/2012/08/disable-nuget-package-restore.html
Also, you might want to double-check that this option is disabled:
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
Isn't it this setting here?
Options... -> Nuget Package Manager -> [uncheck] Allow Nuget to download missing packages
I'm using Visual Studio Professional + Resharper 8.2
Solutions currently using MSBuild-Integrated package restore can be migrated to Automatic Package Restore. From what I understand, this should help those who are encountering CI build issues. (Please correct me if I am mistaken).
Please refer to the document on the nuget website: Migrating MSBuild-Integrated solutions to use Automatic Package Restore at http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore
There is information there for converting with and without TFS.
David Ebbo also posted some information at http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html
We actually have a blog post about it and at the end of the post a powershell script was mentioned to help with the migration.
http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore
NuGet has a blog post about migrating to automatic package restore:
http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore
There is a powershell script referenced in the blog post that will take care of removing the necessary lines automatically (and recursively):
https://github.com/owen2/AutomaticPackageRestoreMigrationScript/blob/master/migrateToAutomaticPackageRestore.ps1
Offering a Disable NuGet Package Restore option directly is marked as Won't Fix:
https://nuget.codeplex.com/workitem/1883
I had the same issue. What I ended up doing:
1) go into each project .csproj file in the solution, open it in notepad then removed the portion of the xml and saved.
2)Then I removed the all of the package.config files in the entire solution.
3)Then I had to remove the .nuget and package folders.
At this point, I had a completely NuGet free solution.
4)Then I manually referenced any needed DLLs and hit compile and the solution ran like a champ without the NuGet packages being needed.
I followed the accepted solution to no avail using 2012. This did work though,
Completely close the VS
Update the <RestorePackages>true</RestorePackages> to <RestorePackages>false</RestorePackages> and delete the <Import Project="$(SolutionDir)\.nuget\nuget.targets" /> line
Also renamed the nuget.exe to nuget.exe.NotExe
For anyone still needing to clean up a project using the old style NuGet package restore, the IFix tool available here automates the process.
Just run the installer (IFix will be added to PATH) and then run the following:
IFix nugetrestore --fix
You can run it in check mode first to see what it will clean up:
IFix nugetrestore --check
Go to your solution directory where you have [$(SolutionDir)\.nuget\nuget.targets]
.nuget folder and nuget.targets file under it delete the folder,
and change remove lines from your csproj for once last time.
The problem won't come back to bug you again.
Remove the packages.config file within your solution.
I accidentally enabled this "package restore" option while opening my project in VS2012 RC and started getting errors that looked something like:
"Error 1 Unable to locate 'C:\FolderX\SomeProject.nuget\nuget.exe'"
To fix the error I followed the above instructions, opened open each project file in notepad and removed that RestorePackage line.
I was able to resolve this issue by taking these steps:
1) make sure you take a backup of all your current checked-out files changes.
2) physically delete the solution folder from your C:\ (path that is mapped to TFS).
3) get latest from TFS for your solution.
4) copy (if any) your changes from the backup you took in step-1.
hope that helps !
I ran into the exact same problem and tried to remove all .nuget and RestorePackage tags from the project files but one project just wouldn't reload not matter how thoroughly I examined it for .nuget and RestorePackages tags. I guess there's some hidden references to this somewhere.
In the end it was easier to just copy the files and create a new project and import it to the solution.
Nuget sucks. Just remove nugets and remove or comment package elements from packages.config in root directory of the projects where this is a problem. Use direct references into some lib folder instead.
<?xml version="1.0" encoding="utf-8"?>
<packages>
<!--<package id="EntityFramework" version="6.0.2" targetFramework="net45" />-->
</packages>

Resources