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.
Related
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.
Usually when I want to debug a nuget package I download the source code and add the .csproj file to my solution and add a project reference instead of using the nuget package. This lets me step through the code and see what is going on with my live project.
I have a nuget package I want to debug but it is very large. I downloaded the source code and the solution has around 20 projects in it. I tried just adding a few of them but ended up with lots of dependency issues.
Is there a way I can tell visual studio that the source code for the nuget package exists on my HD so I can step through it without having to add 20 projects to my current solution? Or perhaps some way to add a reference to the entire solution?
My goal here is to be able to set breakpoints so when the third party compiled code executes I can step through it and see what is going on. What is best way to do this?
Assuming the application is .NET 4.7.2. You could try dnSpy which allows you to debug & edit a built executable/dll.
GitHub Page: https://github.com/0xd4d/dnSpy
Latest Release:https://github.com/0xd4d/dnSpy/releases/download/v5.0.0/dnSpy.zip
Once downloaded
Start up dnSpy.exe for 64-bit or dnSpy-x86.exe for 32-bit applications.
Use File->Open to locate your exe's and dll files.
Apply your breakpoints within dnSpy.
Hit start as you would in Visual Studio
Emcrank has very interesting solution for not having the source code but it wasn't right for me.
The answer for me was actually very simple. When going to add existing project you can change dropdown to add a .sln file. I created a folder then added the solution to it and it pulls everything in with single transaction and now I can easily debug all the code.
the problem is thus. Every time I open a specific solution in visual studio it hangs forever, you get the annoying Visual Studio is Busy popup. The only way to get it to load is starting visual studio in safemode or by deleting the v12.suo file before opening the solution.
Once it's hung all the projects are marked (Initializing) apart from one project that is (loading). This project is from a different solution and from a different place in the tfs tree. If I unload the shared project then VS loads the solution fine, I think the problem is with TFS, can it deal with a project in multiple solutions?
Thanks
You should remove the shared solution and instead share discreet components as Nuget Packages.
I would generally have a Solution & Project for each of my shared groups... Usually there is a relationship between the css, images, and JavaScript... And package each one as a Nuget Package. Add an automated release pipeline and you can have checkin->dependancy in very short order.
I use VSTS and have a Build that creates a Nuget package with the bits I need and then use the release management tools to control visibility and quality of that package. It's then easy to have your packages deployed to a Nuget Repository (I use VSTS) and let any of your internal projects take a dependancy on them.
This will have the added bonus of increasing quality and knowledge of dependancies and interfaces in your devs. Let them have a dumping ground and they will always use one.
You can do below steps to narrow down this issue:
Try invoking Visual Studio from the command line devenv.exe /log. Then try to open your solution and then if it crashes, go look at the
%APPDATA%\Microsoft\VisualStudio\<version>\ActivityLog.xml
file. It will including some details on the crash. Also, the event logs may capture some high level events as well.
I keep running into an issue with our TFS build server. I've got 2 projects (both in the same solution), 1 is a WebForms project, running .Net 4.0. The second is an ASP .Net MVC5 project running .Net 4.5. There is also a Silverlight project, but the problem is reproducible with just the first two.
Both of these projects use NuGet packages for various libraries. Sometimes there are different assemblies within a package for their respective environments. A .Net 4.0, 4.5, SL assembly, etc.
The build server seems to dump all of the libraries required into a single folder, then pulls from that to build the solution. This causes problems in many cases, with the wrong project getting the wrong assembly version. This does not occur locally, only on the build server. I can't figure out what I need to do to keep this from happening. Any ideas?
Yes, I hate this standard behavior, but TFS will output everything to the same folder by default, and then you will get various errors depending on which order msbuild compiles your projects if you have references with the same name or even project outputs with the same name.
The easiest workaround is to use the AsConfigured option on the Process tab, '2. Build' -> 'Output location' of the build definition window. This keeps your normal source structure intact, but I think you will lose support for automatically dropped outputs (i.e. you will have to provide a script to do that yourself). If you are only using TFS Build for validation, this is the cleanest approach.
You can also use the PerProject setting and split up your projects into two distinct solutions, perhaps suffixed by platform (we've done that numerous times in our company). Then, you specify both solutions to the build process and it will create two separate folders in the output, one for each solution.
This is all assuming you are using TFS 2013. In TFS2012, there is a similar option but it is in '3. Advanced' -> 'Solution Specific Build Outputs'. You will probably have to go this route if you are using TFS2012 or you will need to modify the default workflow yourself to add your own logic.
EDIT:
From your comment to the other poster I see you are using TFS 2010. Well... I think this was absolutely not supported at that time, I remember having similar problems, but we upgraded to TFS 2012 and all was well.
I think your only option is to either create two separate build definitions and build each solution that way, or you will need to checkout the xaml workflow and edit it with your own logic. Perhaps downloading the TFS2012 template and "porting" it to TFS2010 would be a better approach since at least you would not be reinventing the wheel that way.
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