© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•8mo ago•
13 replies
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>
    <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
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
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
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>
    <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
Project1
from the single-file binary. But now, after publishing for Release,
Project1.dll
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
.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)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Publish single-file
C#CC# / help
2y ago
Publish to single working .exe
C#CC# / help
2y ago
Help! XmlnsDefinitions in Project-File
C#CC# / help
3y ago