I'm having trouble with the following fact : I cannot add Nlog.config file to the root folder of my .net console application as it gets installed in ...nuget\packages\nlog.config\4.7.7\contentFiles\any\any\NLog.config.
On my machine I can use the property to copy it to the output folder (option "Copy to Output Directory") but it does not help because when I submit my project to Gitlab and it does not include the Nlog.Config because it is either in my output folder of the project, which I don't commit to Gitlab, or in the .nuget folder.
When I run it in AWS, after checking the project out from gitlab, the Nlog.config file is not there, another one by default is used which does not include my modifications.
Could you please help ? Thanks !
EDIT
Ok, I researched a bit more and found out -https://stackoverflow.com/questions/15958271/make-nlog-config-file-load-the-file-from-d-dev-instead-of-bin-debug but still don't understand how to apply it to my example.
EDIT 2
Copying a Nlog.config and Nlog.xsd into the root directory of the project and editing the ConsoleCoreApp1.csproj and replacing :
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<None Update="C:\Users\User\.nuget\packages\nlog.config\4.7.7\contentFiles\any\any\NLog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="C:\Users\User\.nuget\packages\nlog.schema\4.7.7\contentFiles\any\any\NLog.xsd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
...
<ItemGroup>
</Project>
with :
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="NLog.xsd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
...
<ItemGroup>
</Project>
results in the following error when trying to build by command line:
Build FAILED.
"I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj" (publish target) (1) ->
(GenerateSingleFileBundle target) ->
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: System.ArgumentException: Invalid input specification: Found multiple entries with the same BundleRelativePath [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.NET.Build.Tasks.GenerateBundle.ExecuteCore() [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskBase.Execute() [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.NET.Build.Tasks.TaskWithAssemblyResolveHooks.Execute() [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
C:\Program Files\dotnet\sdk\5.0.102\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(1016,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj]
0 Warning(s)
1 Error(s)
EDIT 3
So, finally, my solution of copying manually the files (Nlog.config and Nlog.xsd) in the project's root directory and change the .csproj file to reference them instead of the same files but located into ...\.nuget\packages\nlog.config\4.7.7\contentFiles\any\any\
works, but I have another problem now :
There is a problem with the publish command (the build command is ok). I tried publishing both, from the command line and from Visual Studio 2019 and still get an error.
And this is the output of the error log file which does not help much :
2/12/2021 6:05:32 AM
System.AggregateException: One or more errors occurred. ---> Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.
--- End of inner exception stack trace ---
---> (Inner Exception #0) Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. <---
Microsoft.WebTools.Shared.Exceptions.WebToolsException: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.
===================
The command I used is :
msbuild /t:publish /p:Configuration=Release /p:TargetFramework=net5.0 /p:RuntimeIdentifier=win-x86
.
When I run it in the terminal I get the error mentioned in EDIT 2.