dotnet build with logger - .net-core

If I want to specify a logger where I can set the name and location of the log file, I do the following:
dotnet build /l:FileLogger,Microsoft.Build.Engine;logfile=MyLog.log
This syntax has worjked for me in the past with msbuild, however it is not working with dotnet. What am I doing wrong?

I took me some time to find this, but you can use fileloggerparameters (flp)
dotnet build /flp:v=diag
This will create log file msbuild.log. The Option [v]erbosity is set to [diag]nostic. But you can choose others verbosity levels.
Use the option logfile to specify the name of the log file.
dotnet build /flp:v=diag;logfile=MyLog.log
This also works with msbuild
msbuild /flp:v=diag;logfile=MyLog.log
Using Powershell the command for dotnet looks like
dotnet build /flp:v=diag /flp:logfile=MyLog.log

Related

Set configuration to "Release" when publishing

I have a project that I'm publishing using the dotnet CLI's dotnet publish command.
Since I only ever publish with a release intent, I'd like to make it so that when I issue a dotnet publish the build and publishing happen with the "Release" configuration but still use the "Debug" inside Visual Studio when I'm debugging/testing.
I know I can manually change the configuration from Visual Studio's configuration/properties window and can specify the -c Release argument but is there some tag I can include in my .csproj file that says "when publishing use 'Release' by default"?
Create batch/powershell file for the command
dotnet publish -c Release
save it into release.cmd and run that when needed
There is an opened issue regarding this here.
You may check it, specially this #nguerrera comment.

dotnet command for creating startup project

I want know what is the command line for making a directory a startup project.
I have 2 directories inside EmployeeManagement and on sln file:
Models
Web
Employeemanagement.sln
Now instead of Right clicking and making Web the startup project, is there a way of doing it using command line interface.
Thanks for your help.
In the .Net 5.0, you can do: dotnet run --project , everytime you need to run the project.
CLI Example:
dotnet run --project Web/Web.csproj

how set asp.net core startup project using command line in Vs code

I have multiple projects in my workspace. how I can set a startup project using the command line.
There's no built-in way to set the startup project in a persistent manner, but you can specify the project to run when using dotnet run with the --project option:
dotnet run --project /path/to/project
For changing startup project in VS Code, you should open launch.json file from Explorer window and edit "program" and "cwd" attributes.

How to run and publish .NETCore Xunit tests on VSTS (Vs2017)?

I had two build steps in VSTS:
To run tests (VSTS cmd task): DOTNET test -xml TEST-results.xml
To publish test results step (VSTS test publish task): format=XUnit and the file name from previous step
But after I upgraded to VS2017 the -XML tag is not working anymore. I changed step one to use this:
test --logger "trx;LogFileName=TEST-results.xml"
but the second step throws an error "Invalid results file. Please make sure the Test Result Format field in the task matches the result format of the file"
Is there another way to run .NetCore tests on VSTS? or am I doing something wrong?
Thanks,
starain-MSFT's answer will work, unless you want/need the xunit tests to be logged using an xunit logger. In that case, you'll need to do two things.
Add https://www.nuget.org/packages/XunitXml.TestLogger/1.0.2-pre-rtm as package ref to your test project, either through 'Manage NuGet Packages' in VS, or by adding the ref in your csproj file manually, i.e.
<PackageReference Include="xunitxml.testlogger" Version="1.0.2-pre-rtm" />
Modify the VSTS dotnet test build step to use this logger:
dotnet test -a:. -l:xunit
The -a:. switch, which specifies the adapter path, is only necessary for CLI tools V15.0, in 15.1 that can be removed (as discussed here). As of today, the VS2017 Hosted Queue is using 15.0, so you'll need the -a:. on VSTS for now.
The -l:xunit uses the friendlyname, which I think isn't so friendly since you have to dig into the source code for the particular logger to find the attribute where it is specified (as seen here for xunit and here for trx)
The docs for the -l switch are spotty to say the least, but in the github for vstest, there is a document which talks about test loggers and links to their repositories and nuget packages, which after you look at the source for the friendlyname, gets you all the way there for whichever logger you need. If you need a custom logger, those are great examples to help understand how to implement.
Finally, the publish step that you used originally should be fine, since the output file is still called TestResults.xml
Change "Test Result Format" to "VSTest of Publish Test" result step/task, it reads the result file correctly.
Use dotnet xunit instead of dotnet test. See Getting Started with .NET Core.

dotnet build with profile

Before I can use msbuild command in command line and pass the profile as a parameter. Is this currently supported in dotnet cli or is there a new way to build projects/solutions in .net core projects?
Under the hood, the dotnet cli is now mostly using msbuild to do the actual work (excluding dotnet new and dotnet run). So if you're doing a dotnet build, it's actually using msbuild internally.
You can still use msbuild parameters when using the dotnet cli, you need to use the following:
dotnet msbuild <options>
One option is /property:n=v which passes in your property name/value pairs directly to msbuild as you used to do with msbuild itself. You can also continue to use semi-colons between pairs, e.g.:
dotnet msbuild /property:WarningLevel=4;Configuration=Release

Resources