C#C
C#6mo ago
peppy

Behavior of ``<Private>false</Private>`` project refs in single-file publish

I have an executable project with the following constraints:
    <PropertyGroup>
        <OutputType>Exe</OutputType>
    </PropertyGroup>

    <ItemGroup>
        <!-- This dependency is shared with 10-15 other projects. -->
        <ProjectReference Include="Project1.csproj" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="SOME_PACKAGE" Version="SOME_VERSION" />
        <!-- ... many more packages. All of these are private to this executable. -->
    </ItemGroup>

and I would like to publish it as a single file to avoid the clutter of many, many package dependencies. This works fine at first.

However, Project1.csproj is a very large library and a shared dependency with every other project in the solution. Embedding it within the single file makes no sense.
I would like not to embed Project1 within the single file (because it is shared with every other project), while embedding all of the PackageReferences (because they are private to this executable).
When the wider solution is built, a copy of Project1.dll (with all of its dependencies) will be placed in the same folder as the single-file binary. So the dependency can be met at runtime.

Thus I figured I can rewrite the ProjectReference as:
    <ItemGroup>
        <ProjectReference Include="Project1.csproj">
            <Private Condition="'$(Configuration)'=='Release'">false</Private>
            <ExcludeAssets Condition="'$(Configuration)'=='Release'">runtime;native</ExcludeAssets>
        </ProjectReference>
    </ItemGroup>

Doing so removes the embedded Project1 from the single-file binary. But now, after publishing for Release, Project1.dll 'cannot be found' despite being placed in the same folder as the single-file binary.

Why is that? How can I inspect the .deps.json of the resulting single-file binary? Is there a way to achieve what I want? (private dependencies are packed; shared dependencies are not)
Was this page helpful?