.net 核心 (csproj) global.json 'projects' 等效项

编程入门 行业动态 更新时间:2024-10-23 08:39:16
本文介绍了 核心 (csproj) global.json 'projects' 等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 core (project.json) 我曾经通过将源代码的路径添加到 global.json 中的 projects 字段来在 nuget 包和源代码之间切换.在我这样做之后,它将添加它可以在该路径中找到的所有项目,这些项目可以替换我引用的 nuget 包.

With core (project.json) I used to switch between nuget packages and source code by adding the path to source code to the projects field in the global.json. After I did that it would add all the projects that it could find in that path that could replace the nuget packages I referenced.

我经常使用此功能,因为我有自己使用的 nuget 包,但我想在发布之前测试其他项目中的更改.但是一旦我切换到 Sdk 1.0.0/VS 2017/csproj 核心,该功能似乎就消失了.

I used this feature alot because I have my own nuget packages that I use, but I want to test the changes in my other project before I publish. But once I switched to Sdk 1.0.0/VS 2017/csproj core that feature seemed to disappear.

另一种方法是手动添加每个项目,手动切换引用(因为它们被分解为项目、nuget 和 sdk 引用),然后全部切换回来.

The alternative is just manually adding each project, switch the references manually (since they are broken up into project, nuget and sdk references), and then after switch it all back.

任何想法或建议都会很棒.

Any thoughts or advice would be great.

更新:听起来在 csproj 中没有等价物(正如预期的那样),但目前有 msbuild 解决方法(从最初的 VS 2017/.NET Core SDK 1.0.0 版本开始)

UPDATE: Sounds like there is no equivalent in csproj (as expected), but there are msbuild workarounds for now (As of the initial VS 2017/.NET Core SDK 1.0.0 release)

推荐答案

是的,我也已经习惯了这个功能,并围绕它构建了我的工作流程.我仍在寻找解决方案,但我目前正在考虑在 csproj 文件中使用条件逻辑的想法.由于现在是 msbuild,你可以这样做:

Yes, I too had gotten used to this functionality and built my workflow around it. I am still looking for a solution but I'm currently playing with the idea of using conditional logic in the csproj files. Since it's now msbuild, you can do things like this:

<Choose> <When Condition="Exists('......MyProject')"> <ItemGroup> <ProjectReference Include="......MyProjectsrcMyProjectMyProject.csproj" /> </ItemGroup> </When> <Otherwise> <ItemGroup> <PackageReference Include="MyProject" Version="1.0.0" /> </ItemGroup> </Otherwise> </Choose>

这会将对包的硬引用替换为条件,如果它可以找到源代码(在本例中为目录),则使用项目引用,如果找不到,则使用包引用.

This replaces the hard reference to a package with a conditional that uses a project reference if it can find the source code (in this case the directory), and a package reference if can't.

因此,默认情况下您将引用包,但如果您想调试您的项目之一,您可以在条件检查的位置将其签出,并将项目添加到您的解决方案中.

So by default you would be referencing the package, but if you want to debug one of your projects, you check it out in the location that the conditional checks, and add the project to your solution.

这样,您只需在想要包含源代码时更改解决方案文件(通过添加项目),而不是重新连接所有项目引用.

This way you only need to change your solution file (by adding the project) when you want to include source code, instead of rewiring all your project references.

更多推荐

.net 核心 (csproj) global.json 'projects' 等效项

本文发布于:2023-11-14 09:19:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586826.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:核心   csproj   net   global   projects

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!