Dotnet build behaves differently when executed from TeamCity - c#

We're seeing a Lucene.NET analyzer build warning that shouldn't be there when executing dotnet build for one of our ASP.NET Core 3.1 web apps. The strange thing is that this warning seems to happen only when executed with the .NET runner in TeamCity; it (correctly) doesn't happen when running the dotnet build command directly from a PowerShell runner, or from the PowerShell console on the same machine (with the same user account, same folder, same code).
The build warning is actually due to a bug (that was fixed in a later Lucene.NET version) but the point is that we see different behavior.
We have tried running the exact same command that's displayed in the Build Log, including passing the TeamCity-generated RSP file to it. Still, outside of the .NET runner we can't reproduce the warning. We confirmed that the same user account runs the process, uses the same NuGet cache and dotnet.exe (and .NET SDK), runs in the same folder for the same code, with the same parameters.
The only thing we can think of is that somehow the .NET Plugin executes dotnet build differently but in a way that's invisible from the Build Log. However, we are out of ideas what else to try or investigate.
Could you help pinpoint where the difference in the two builds could be? Thank you in advance!
I've previously asked this on the TeamCity forum but didn't get a reply.

We ended up just running dotnet build directly, not using the .NET Runner. It has also cut certain builds' times down drastically (40-50% where there were a lot of build warnings).

Related

Is it possible to debug a C# console application using git bash?

I am using Visual Studio Community 2022, and I was wondering if you could use another CLI to run/debug a c# console application. (I can't use cmd.exe or powershell because it's blocked by the admins of the device I'm using). Git Bash would be preferred, because it's already installed. Thank you!
Edit: Looks like you can't do this. dotnet run just tries to open the blocked binary, no matter where you run it. I think the admins hate everyone though because they allow you to install lots of things (like Unity, vscode, etc.) but running anything just doesn't work.
Thanks for trying everyone!
use this to run your program in CLI but you cannot debug it if you want to debug use debugger mode of vs2022,
If it's a framework-dependent application (the default), you run it by dotnet yourapp.dll.
Run the project in the current directory:
dotnet run
check Microsoft Docs dotnet run for more options.
CLI: Use Vs2022 Terminal in View->Terminal it may help You to run it.

Running an executable independently and simultaneously with "dotnet watch run"

I have an ASP.NET Core 5 project that as the main function runs a typical ASP.NET web project. So typically I start it with dotnet watch run and the server runs in the background continuously. But I'm also trying to add a way to execute console commands to the same executable, which reuse the code from the server version but don't start the actual WebHost from ASP.NET. The command line version should be able to run either with the server version already running, or entirely standalone.
The problem now is that I'm quite obviously doing something that dotnet run wasn't meant for, because the build is extremely flaky and fails quite often with unhelpful errors (e.g. file access errors, . It does make sense that running dotnet run again while it's still running in the background isn't a supported case, so I'm trying to find a different way to do this.
The whole thing runs inside Docker, though this probably doesn't change anything for my specific problem. I'm using VS Code, so Visual Studio specific solutions would not work for me, it must run with the dotnet CLI alone.
What I want to do is to have a dotnet watch run in the background during development, and a way to just execute the binary it built separately without triggering a simultaneous build that leads to problems. At least as far as I can tell this should avoid the issues I've been running into, if I'm wrong here and running simultaneous dotnet run or dotnet watch run should not cause build issues, please correct me here. I assume that running a separate dotnet build would run into the same issues, and I could not see anything in the dotnet CLI documentation that would fit my use case.
How can I safely run my project in development a second time while it is still running via dotnet watch run in the background?
A quick workaround is to use different build configurations (i.e. dotnet watch run -c Debug and dotnet run -c Release). If you haven't overridden the default output directory (./bin/<configuration>/<framework>/), you will be effectively using two compiled versions of the application, avoiding those 'flaky builds'.
You could also create your own build configuration for this purpose (i.e. dotnet run -c My_Debug) and configure it to have 'debug' properties, avoiding having to use the default Release configuration.

Unable to find testhost.dll. Please publish your test project and retry. (.Net Core 2.1)

I have a C# (selenium + NUnit + Specflow) .Net Core 2.1 project (vs 2017).
My project references the Microsoft.TestPlatform.TestHost nuget which contains the testhost.dll. The tests run on my computer but when I try to run them in Azure DevOps they fail with the error, "Unable to find testhost.dll".
This makes sense because when I build the project on my computer, testhost.dll is not added to the bin directory although the project references the Microsoft.TestPlatform.TestHost nuget which contains the testhost.dll.
Question: Why does the testhost.dll not get added to the bin directory on build?
Note: I have looked at other posts about this error message and most of the time their problem is that they are not referencing the assembly. However, I am referencing the nuget.
Project does reference testhost.dll
Microsoft.TestPlatform.TestHost is in the *.csproj file
when run on command line on my computer it runs fine (testhost.dll is not needed when run on my machine because VS is installed)
When run in Azure Pipeline, it fails stating testhost.dll could not be found (which makes sense since it never gets copied to the bin directory. Not sure why it doesn't get added to the bin though)
This is more than likely the issue. I copied the files to the artifact instead of publishing. I'll test and see if this works. Will update this post after I try this out. [Update: Yes, the issue was that I needed to publish in order for the needed *.dlls to get placed into the bin directory]
Answer in the image came from the following github page.
These are the Instructions I was following. They were actually really good. I used it to get comfortable running a test project in azure before integrating it into a software pipeline. You'll see minute 11:33 shows that the tests need to have a 'Publish' step in the job.
How to Run .NET Core Selenium Tests in Azure DevOps
Just run the Publish task (dotnet or msbuild) prior to the test execution and use the test libraries from your publish location.

.Net project static code analysis through Jenkins and SonarQube

What I Need -
Dears - I am in process of creating a Jenkins Job for my .Net Solution. The solution has an ASP.NET web application project and a Winforms Project along with several other class libraries,
As a part of the Jenkins job execution, I would also want to perform Static code analysis for which I would be executing SonarQube runner as 'Pre' and 'Post' Build steps.
What have I done so far -
It is to be noted that, I have already installed all of the tools (Jenkins, SonarQube services) and all of the needed plugins (MSBuild, C#, Javascript, Powershell, SonarQube runner etc.,)
I could see that my job executes successfully. Build is good and SonarQube scanner also ran without any issues.
The problem -
Post successful build and analysis, I am seeing analysis report only for ASP.NET web application project in my SonarQube Dashboard. But I am interested only in the Winforms project.
My build is done through MSBuild.exe and I am pointing to the Solution file. Please note that the Winforms project is my Startup project. But nevertheless I could see that SonarQube runner is picking only ASP.NET project for analysis.
My Question -
If someone could tell me how to get the results of the Winforms project it would be great. Let me know, if I am lacking any bit of information. I can provide them.
Thanks in advance - Happy Coding !!!
EDIT - I don't have any projects in the exclusion list. Just the default test projects.
Attaching my MSBuild default exclusion list.

Building C# project using jenkins

First of all, im not sure if there is a specific forum thats more suitable for request about Jenkins, but I figured I just post it here.
So, I have this C# project, it right now requires Visual Studio 2015 to build and I would like to automate builds with Jenkins. This is the first time I'm using Jenkins and I was able to set it all up, it fetches the code from the gitlab repository, but right now there is no build action configured. For "fun" i tried to simply make it use a "windows batchfile" as build file and added echo test. Checking the console output it downloads the repository code and then tries to execute the batchfile, result is:
java.io.IOException: Cannot run program "cmd" (in directory "/var/lib/jenkins/workspace/Project"): java.io.IOException: error=2, No such file or directory
This of course makes sense, but I wonder now, is there a way to build a C# project with jenkins on a debian server without resorting to mono or something? I know that people build C++ projects for windows with Jenkins on a linux root, so there has to be some sort of cross compiling possibilities.
If the Visual Studio 2015 is a dealbreaker I can also strap it down to VS13 or even below. Any help is greatly appreciated!
/EDIT
Its probably important to say that Mono is NOT an option. Im using features like WPF that are not available for Mono.
Use Jenkins' MSBuild plugin.
Jenkins.NET is a good blog about using Jenkins in a .NET environment. First post is here.

Categories