.net core (csproj) global.json 'projects' equivalent

后端 未结 2 2007
悲哀的现实
悲哀的现实 2020-12-28 20:04

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

相关标签:
2条回答
  • 2020-12-28 20:37

    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.

    0 讨论(0)
  • 2020-12-28 20:55

    For others that are interested in attempting to emulate with Global.json did, I worked around this for now using a couple powershell scripts and a custom json file that mimics it. Check out my answer here: https://stackoverflow.com/a/43795974/5504245

    0 讨论(0)
提交回复
热议问题