C# Nuget 包输出位置提示 [英] C# Nuget package output location advise

查看:27
本文介绍了C# Nuget 包输出位置提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个教育项目,但在组织该项目时遇到了困难.在过去的三天里,我一直试图找到解决方案,但还没有找到.我试图使构建输出尽可能干净和有条理.

I'm working on a project for education and have a hard time with organizing the project. For the past three-days i have been trying to find a solution but haven't found any yet. I am trying to make the build output as clean and organized as possible.

问题我已经加载了两个 nuget 包以及它们的依赖项.因此,当我构建项目时,所有 DLL 文件都在配置文件(调试或发布)的主/根目录中创建.

The issue I have loaded two nuget packges with both their depedencies. So when i build my project, all the DLL files are being created in the main/root directory of the configuration profile (Debug or release.)

**Issue Terminal/bin/Debug/net5.0:**
/Core.dll (Project reference)
/MySql.Data.dll
/Terminal.Gui.dll
/Dependency1.dll
/Dependency2.dll
/Dependency3.dll
/Dependency...dll```

**Goal Terminal/bin/Debug/net5.0:**
/bin/server/Core.dll (project reference)
/bin/packages/MySql.Data.dll
/bin/packages/Terminal.Gui.dll
/bin/packages/Dependency1.dll
/bin/packages/Dependency2.dll
/bin/packages/Dependency4.dll
/bin/packages/Dependency....dll

推荐答案

将这些写入 csproj 文件:

<Target Name="CopyToDesintation" AfterTargets="Build">
        <Copy SourceFiles="@(RuntimeCopyLocalItems)" DestinationFolder="$(TargetDir)bin\packages"></Copy>
        <Copy SourceFiles="$(TargetDir)Core.dll" DestinationFolder="$(TargetDir)bin\server"></Copy> 
</Target>

然后,重建您的项目以进行检查.

Then, rebuild your project to check it.

更新

请覆盖_CopyFilesMarkedCopyLocal系统默认目标

1) 在项目文件夹中创建一个名为 Directory.Build.targets 的文件:

1) create a file called Directory.Build.targets file on the project folder:

2) 将这些添加到该文件中:

2) add these on that file:

<Project>

    <Target Name="_CopyFilesMarkedCopyLocal">
        <Copy SourceFiles="@(RuntimeCopyLocalItems)" DestinationFolder="$(TargetDir)bin\packages"></Copy>
        <Copy SourceFiles="@(ReferenceCopyLocalPaths)" DestinationFolder="$(TargetDir)bin\server"></Copy>
        
    </Target>

</Project>

虽然 server 文件夹包含包 dll,但您不需要,dll 不在根文件夹中.这是我找到的最好的功能.

Although server folder contains the package dlls, it does not matter your need and the dlls are not in the root folder. And this is the best function I have ever found.

这篇关于C# Nuget 包输出位置提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆