Dotnet CLI fails building after mv to other directory? - c#

Currently, I'm doing my second day of my first internship at a smaller company where I have to build something in C#. Except from Unity, I've never used C# before so I'm kinda new in using it. I'm currently using it on Linux Ubuntu 20. So forgive me for this most likely beginner question.
I'm using dotnet-sdk to build calling "dotnet clean; dotnet build; dotnet ~/pathToDLL/etc/etc". I've finally got something working now, So I cloned the empty git repository from the company and used the mv command to move my directory with some working code to the git repo. Now, when I try to build it it gives the following errors:
/snap/dotnet-sdk/107/sdk/5.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5):
error NETSDK1004: Assets file '/home/oscar/
Tacho/card_reader/obj/project.assets.json' not found.
Run a NuGet package restore to generate this file.
[/home/oscar/Tacho/card_reader/card_reader.csproj]
It gives more or less the same error twice.
/snap/dotnet-sdk/107/sdk/5.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5):
error NETSDK1004: Assets file '/home/oscar/
Tacho/card_reader/obj/project.assets.json' not found.
Run a NuGet package restore to generate this file.
[/home/oscar/Tacho/card_reader/card_reader.csproj]
For most users reading this error, this is probably an easy fix. But as I said, I've zero experience using C# on Linux (or Windows) outside of the context of Unity. So any explanation and fix will be very much appreciated!
Oscar
solved
There was a space somewhere in the directory I copied my working code to. I removed this space (and everything before it) for this question because there was company sensitive information there which my boss didn't want to see end up on the internet. Because of the space (in the git repo name) Linux obviously had errors executing commands. Thanks to everyone for the help.

The error seems to indicate that a NuGet package is missing some files. NuGet is a popular library distribution system that is also built into Visual Studio. Even an empty repository may be referencing the package as a dependency or your own code may be using that it. If you are using Visual Studio you can do the following:
Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages.
In Solution Explorer, right click the solution and select Restore NuGet Packages.
Your company might be using a private NuGet server though, so you will want to make sure you are connected to any VPN services. Also do not be shy about asking a co-worker about this issue. This is likely part of configuring your environment properly and not something you are expected to 'just know' as a new intern.

Related

Unable to find NuGet packages despite packages being installed NU1101

I created my first C# application recently, and since buying a new computer I cannot get the application to start.
I am receiving 7 of the following errors Error NU1101 Unable to find package Microsoft.VisualStudio.Web.CodeGeneration.Design. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages clesson C:\Users\porkh\Desktop\WERK\Personal\c-lesson\clesson\clesson\clesson.csproj
Each with different packages missing.
Since this was a missing dependencies message I reinstalled visual studio 2019 with C# .net support again, yet I am running into the same error.
On StackOverFlow I read that I need to check my NuGet packages,
Here it shows every package that is "missing" in the error messages as installed.
I have also tried running dotnet run and dotnet restore but I get the same error messages.
I am extremely new to C# so sorry if I have missed the solution in other's answers. Any help you can give me I'd appreciate it.
A link to all of my project files here
In the image it says
Not available in this source
and the package source is set to Offline Packages. My best guess is, switching to an official NuGet Feed in the drop down to the upper right, will solve your problem. You also want to check, if the Nuget source is available (it should).
If not, click the Cog icon, and add it there with the name "Nuget" and the Url https://api.nuget.org/v3/index.json

Visual Studio-Code is not finding Library

I am setting up a simple console project to connect to a database using a connection string. My problem is the project is NOT finding one of the required libraries at runtime.
When I run the console app the application fails.
I go look at the csproj file to ensure I have added the library. I run the command 'dotnet restore -force'. and it finds the library and reports no errors.
The same code works on other developer machines (Windows laptops) but it does not work on my MAC. I am using NuGet Package Manager and NuGet Gallery to ensure I have installed them correctly. I have uninstalled the libraries and re-installed them. It still does not work.
Have I done something wrong? Any suggestions or recommendations would be helpful.
After a lot of searching I found a work around.
I change the usage from System.Extensions to MicroSoft.Extensions.Configuration. I followed the instructions form this question on how to get the connection string.

Reference dll 's are missing from the solution after going for new work space or branching

I created the MVC application and build the solution in my local machine and it builds without error then I have uploaded that MVC application into TFVC. But, if i take a new workspace from the other developer machine or going for the Branching feature in TFVC, we have been endup with all the reference dll's which was showing deleted like below screen shot and the solution does not build successfully. We are not sure what its causing the issue. Please help us to resolve this issue. Thanks in advance.
Update
Actual problem i am facing here is, I run update-package -reinstall command in the Package Manager Console, it removed all the existing dll's and restored back all the dll and build successfully. But, After successful Build, I have checked-in the pending changes into TFS. But again if I am taking the new workspace from another developer machine, i am still endup with the same build error and missing reference like above screen shot again i have to go for the Nuget Package Restore. Is it a Correct approach? Appreciate your thoughts on this.
right click on the solution and select restore nuget package this may solve your issue then clean and build
check dot net framework version in both tfs and local version
you can also try
update-package -reinstall command to reinstall all referenced packages.
I think you should try restoring missing NuGet packages, check that the option is checked in VS Settings > NuGet.

failed to remove Microsoft.Bcl.Build.Tasks.dll

I am having an issue with my ASP.NET Web-Api solution where my build agent cannot clean its working directories because the library Microsoft.Bcl.Build.Tasks.dll is still in use by some process so it cannot be deleted. The only things I do in my build agent are to build the solution using standard MSBuild.exe, and then I run a few unit tests using MSTest.exe.
I notice that Microsoft.Bcl.Build version 1.0.14 (the version im using) is listed as a dependency by the Microsoft.Net.Http and also by Microsoft.Bcl libraries.
My workflow in the agent is like this:
clone a git repo to the agent
build the solution using msbuild
test the solution using mstest
some time later, maybe 10 minutes, I try and clean up the current iteration
cleaning of the files fails due to the described error
My question is this:
Does anyone know why is this library in use by some process even after many minutes? Is there a common process on windows that would be using this library in the background? I would use the process manager to find why this file was in use, but these build machines are considered to be production boxes and are nearly impossible to get admin access to.
Thanks in advance for the help!
First delete any usages from processes via a program like LockHunter, then restart VS. It worked for me
If your solution contains custom msbuild targets and those same msbuild targets are in use by another csproj in the same solution, you'll run into a conflict at compile time. Effectively, you'd be trying to compile a part of the compilation process mid-compile and you'll run into these types of file lock errors. The workaround is to split your custom msbuild target project(s) out into a separate solution and build them as-needed. I think you'd need to unload & reload the project that depends on the msbuild targets anytime you rebuild them. Once or twice, I needed to restart VS.
If you didn't add any custom msbuild tasks, you can figure out what is causing the problem by looking at the installed NuGet packages. Right click on your solution and click 'Manage NuGet Packages'. Try to remove Microsoft.Bcl.Build from the Installed packages list. It should fail because something depends on it. Make note of what package depends on it. If the first suggestion didn't help, post back a comment with which packages depend on it and I'll see if I can dig up/remember where else I've seen this before.
This question has more details & links about what Microsoft.Bcl.Build is and what it's used for if you're interested: What does the Microsoft.Bcl.Build NuGet package do?
I just came across the same problem on my gitlab build server which does a git fetch before every build set.
After adding Microsoft.Bcy.Async from nuget to my project, the step after the build failed with warning: failed to remove packages/Microsoft.Bcl.Build.1.0.14/tools/Microsoft.Bcl.Build.Tasks.dll
With LockHunter I identified several msbuild.exe tasks.
With that info I found the solution here on so: https://stackoverflow.com/a/12193759/98491
Long story short: the msbuild processes are kept open to improve performance while building. This can be disabled by setting the environmentvariable MSBUILDDISABLENODEREUSE=1 or passing /nodeReuse:false to your msbuild itself.
That fixed it for me.

Visual Studio restoration of Nuget packages through TFS

Today I ran in to a problem that took me a little while to figure out because of my apparent misunderstanding of how the Enable NuGet Package Restore worked within source controlled projects in TFS. So to start out with let me explain the issues that I have spent the last week or so troubleshooting.
On our TFS server, I created a build definition for continuous integration. When the source code is checked-in, the build server begins compiling the source and then fails due to not being able to fetch NuGet packages. I thought initially that it was due to Enable NuGet Package Restore being disabled, so I switched it on at the solution level and re-committed my code. The builds continued to fail. Without having admin access to the Virtualized Instance of the build server, and the admin being swamped lately I let moved on and decided I'd deal with it in a couple of weeks when my Sprint and his Sprint lightens up. Getting the build server up and running is not a must at the moment. I did however remove my local mapping to the branch in TFS, delete the local directory, re-map the source code and perform a fresh get and re-compiled the source without any problems. The NuGet packages downloaded just fine.
Today however we had a new-hire join the team. He pulled a fresh copy from TFS and encountered some SlowCheetah (for transforming our WPF App Configs) NuGet failures. We spent a good chunk of time today trying to figure out why his wasn't pulling down the files properly. After a little while, I right clicked on his solution and noticed that the Enable NuGet package Restore option was available. Even though on my solution, I had enabled it, his solution did not have it set up. I enabled it and immediately his solution compiled without error.
So now down to the primary question, if I enable the solution to restore packages why do I have to re-enable it on another box? I was under the assumption that by making sure Allow NuGet to download missing packages during build option is enabled in settings on all of the boxes, Visual Studio would automatically download the NuGet packages missing from my TFS source code. This confuses me and I would appreciate some clarity on how NuGet should work (and be restored) when packages are used in a project stored in TFS. We are not including any of the packages with our TFS check-ins because I though this feature was supposed to automatically work for the project.
Lastly, I am wondering if this is why my build server is failing to run my build definition. I am getting the NuGet errors and am not sure how to tell the build definition to download the NuGet packages. Is this something I need to do by modifying the build template, adding a sequence to download NuGet packages prior to running MSBuild or something?
Thanks in advance.
Edit 1 I would like to also mention that the NuGet .targets file is included in the TFS branch as well.
This is called Package Restore Consent and for the IDE you need to do it per user. There is a way to override per machine, but its easier per user.
For servers you can use the EnableNuGetPackageRestore environment variable with a value of 'true'
Find out more on: http://docs.nuget.org/docs/reference/package-restore

Categories

Resources