问题描述
使用.net核心(project.json),我曾经在nuget包和源代码之间进行切换,方法是将源代码的路径添加到全局 projects
字段中。 json。完成之后,它将添加在该路径中可以找到的所有项目,这些项目可以替换我引用的nuget包。
With .net 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 .net核心,该功能似乎就消失了。
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 .net 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="..\..\..\MyProject\src\MyProject\MyProject.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 core(csproj)global.json'项目'等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!