根项目文件夹中缺少 Nlog 配置
Nlog configuration missing from the root project folder
我遇到以下问题:我无法将 Nlog.config 文件添加到我的 .net 控制台应用程序的根文件夹,因为它安装在 ...nuget\packages\nlog.config.7.7\contentFiles\any\any\NLog.config.
在我的机器上,我可以使用 属性 将它复制到输出文件夹(选项“复制到输出目录”)但它没有帮助,因为当我将我的项目提交到 Gitlab 时它没有包括 Nlog.Config 因为它在我的项目输出文件夹中,我没有提交给 Gitlab,或者在 .nuget 文件夹中。
当我在 AWS 中 运行 它时,从 gitlab 检出项目后,Nlog.config 文件不存在,默认使用另一个不包括我的修改的文件。
你能帮忙吗?谢谢!
编辑
好的,我进行了更多研究并发现了 -https://Whosebug。com/questions/15958271/make-nlog-config-file-load-the-file-from-d-dev-instead-of-bin-debug 但仍然不明白如何将它应用到我的示例中。
编辑 2
将Nlog.config和Nlog.xsd复制到项目的根目录并编辑ConsoleCoreApp1.csproj并替换:
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<None Update="C:\Users\User\.nuget\packages\nlog.config.7.7\contentFiles\any\any\NLog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="C:\Users\User\.nuget\packages\nlog.schema.7.7\contentFiles\any\any\NLog.xsd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
...
<ItemGroup>
</Project>
与 :
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="NLog.xsd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
...
<ItemGroup>
</Project>
尝试通过命令行构建时导致以下错误:
Build FAILED.
"I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj" (publish target) (1) ->
(GenerateSingleFileBundle target) ->
C:\Program Files\dotnet\sdk.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.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.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.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.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.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.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.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)
编辑 3
所以,最后,我的解决方案是手动复制项目根目录中的文件(Nlog.config 和 Nlog.xsd)并更改 .csproj 文件以引用它们而不是相同的文件但位于into ...\.nuget\packages\nlog.config.7.7\contentFiles\any\any\
有效,但我现在有另一个问题:
发布命令有问题(构建命令没问题)。我尝试从命令行和 Visual Studio 2019 发布两者,但仍然出现错误。
这是错误日志文件的输出,没有多大帮助:
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.
===================
我使用的命令是:
msbuild /t:publish /p:Configuration=Release /p:TargetFramework=net5.0 /p:RuntimeIdentifier=win-x86
.
当我在终端中 运行 它时,我收到 EDIT 2.
中提到的错误
所以,最后,我的解决方案是手动复制项目根目录中的文件(Nlog.config 和 Nlog.xsd)并更改 .csproj 文件以引用它们而不是相同的文件但位于进入 ...\.nuget\packages\nlog.config.7.7\contentFiles\any\any\
作品。
现在,在从我的 .csproj 文件中删除 PublishSingleFile 和 SelfContained 属性后,构建和发布命令都可以工作了:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
</PropertyGroup>
...
</Project>
和
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
...
</Project>
以及msbuild publish
命令成功的证明:
以及 运行 应用程序与日志文件的证明:
我遇到以下问题:我无法将 Nlog.config 文件添加到我的 .net 控制台应用程序的根文件夹,因为它安装在 ...nuget\packages\nlog.config.7.7\contentFiles\any\any\NLog.config.
在我的机器上,我可以使用 属性 将它复制到输出文件夹(选项“复制到输出目录”)但它没有帮助,因为当我将我的项目提交到 Gitlab 时它没有包括 Nlog.Config 因为它在我的项目输出文件夹中,我没有提交给 Gitlab,或者在 .nuget 文件夹中。
当我在 AWS 中 运行 它时,从 gitlab 检出项目后,Nlog.config 文件不存在,默认使用另一个不包括我的修改的文件。
你能帮忙吗?谢谢!
编辑
好的,我进行了更多研究并发现了 -https://Whosebug。com/questions/15958271/make-nlog-config-file-load-the-file-from-d-dev-instead-of-bin-debug 但仍然不明白如何将它应用到我的示例中。
编辑 2
将Nlog.config和Nlog.xsd复制到项目的根目录并编辑ConsoleCoreApp1.csproj并替换:
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<None Update="C:\Users\User\.nuget\packages\nlog.config.7.7\contentFiles\any\any\NLog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="C:\Users\User\.nuget\packages\nlog.schema.7.7\contentFiles\any\any\NLog.xsd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
...
<ItemGroup>
</Project>
与 :
<Project Sdk="Microsoft.NET.Sdk">
...
<ItemGroup>
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="NLog.xsd">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
...
<ItemGroup>
</Project>
尝试通过命令行构建时导致以下错误:
Build FAILED.
"I:\workspaceVS\net50\ConsoleCoreApp1\ConsoleCoreApp1.csproj" (publish target) (1) ->
(GenerateSingleFileBundle target) ->
C:\Program Files\dotnet\sdk.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.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.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.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.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.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.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.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)
编辑 3
所以,最后,我的解决方案是手动复制项目根目录中的文件(Nlog.config 和 Nlog.xsd)并更改 .csproj 文件以引用它们而不是相同的文件但位于into ...\.nuget\packages\nlog.config.7.7\contentFiles\any\any\
有效,但我现在有另一个问题:
发布命令有问题(构建命令没问题)。我尝试从命令行和 Visual Studio 2019 发布两者,但仍然出现错误。
这是错误日志文件的输出,没有多大帮助:
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.
===================
我使用的命令是:
msbuild /t:publish /p:Configuration=Release /p:TargetFramework=net5.0 /p:RuntimeIdentifier=win-x86
.
当我在终端中 运行 它时,我收到 EDIT 2.
中提到的错误所以,最后,我的解决方案是手动复制项目根目录中的文件(Nlog.config 和 Nlog.xsd)并更改 .csproj 文件以引用它们而不是相同的文件但位于进入 ...\.nuget\packages\nlog.config.7.7\contentFiles\any\any\
作品。
现在,在从我的 .csproj 文件中删除 PublishSingleFile 和 SelfContained 属性后,构建和发布命令都可以工作了:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
</PropertyGroup>
...
</Project>
和
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
...
</Project>
以及msbuild publish
命令成功的证明:
以及 运行 应用程序与日志文件的证明: