-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to keep referenced Assembly out of Build Directory? Private not working #4371
Comments
Any progress on that? We're struggling with this issue as well. Always trashes our modules folder which should only contain the module libraries as their dependencies are resolved at runtime anyways. Can't believe that something so simple still hasn't made it into the toolchain. |
I found answer here |
We also have the problem that project dependency spams our output folders unnecessarily, even when with
The PrivateAssets=all workaround seems only to apply to nuget PackageReference - not to project dependency references. |
You have to apply the
Source of this information is https://curia.me/net-core-transitive-references-and-how-to-block-them/ |
How is this still not fixed? It was working fine with the old csproj format. |
I have found a workaround for this by adding DisableTransitiveProjectReferences to the project settings. |
+1 This is so frustrating |
None of the recommended workarounds worked for me. I only see two viable options:
Both of these are ridiculous and shouldn't be necessary. |
@ds5678 If you set |
I think that only works for nuget references. |
+1
Referenced project will not be copied but dependecies of the project will copied to output |
I've taken to explicitly referencing the project's assembly instead of the project in this case. <ItemGroup Condition=" '$(TargetFramework)' == 'net60'">
<Reference Include="$(SolutionDir)MarkdownMonster\\bin\\$(Configuration)\$(TargetFramework)\\win-x64\\MarkdownMonster.dll">
<Private>false</Private>
</Reference>
</ItemGroup> Using None of the other things suggested ( I fail to see why a project reference should not work the same as a another reference using the same settings. At the end of the day the end result that is expected is the same and you should be able to use a direct reference, Nuget reference or project reference pretty much interchangeably. |
Ok, i will try this too But maybe it's still a bug after all that referencing a project works different from referencing a dll/assembly/package. |
i am heading the same issue atm and its really frustrating that a workflow that is even documented here (https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support#simple-plugin-with-no-dependencies) is not working cause of that issue |
I dont know why, but this ended up working for me: In the library .csproj:
When you test, make sure to clean the output folder or you might think it does not work. |
@80O Your hint path looks like it will not work if you clean your solution and build it with "Release" configuration. |
@80O The syntax you want is this: <ItemGroup>
<Reference Include="$(SolutionDir)MarkdownMonster\bin\$(Configuration)\$(TargetFramework)\win-x64\MarkdownMonster.dll">
<Private>false</Private>
</Reference>
</ItemGroup> This works, but it shouldn't be this hard. There's no reason we shouldn't be able to reference the Especially since none of the tooling (Visual Studio, Rider etc.) will set this up correctly if you set Copy Local to false. The no Copy Local is sort of an edge case - typically for Addins or pluggable components - but this should still work and it seems to me this syntax should just work: <ItemGroup>
<Reference Include="$(SolutionDir)MarkdownMonster\bin\$(Configuration)\$(TargetFramework)\win-x64\MarkdownMonster.dll">
<Private>false</Private>
</Reference>
</ItemGroup> |
@RickStrahl can you give an example of a project that is behaving as you describe? I set up a small demo at https://github.com/rainersigwald/demo-msbuild-4371, and put up rainersigwald/demo-msbuild-4371#1 to show how I solved the problem you're describing, which didn't require any of the reference juggling. I would like to discourage people from replacing |
@rainersigwald In your example it would be enough to set |
The conversation moved through a few channels, but @RickStrahl confirmed that you can accomplish the goals
With a few properties and metadata entries:
|
As a follow up - the solution appears to be in this declaration to reference the main project: <ItemGroup>
<ProjectReference Include="../../MarkdownMonster/MarkdownMonster.csproj">
<Private>false</Private>
<ExcludeAssets>all</ExcludeAssets>
</ProjectReference>
</ItemGroup> It also works with
This generates only the local project main assembly plus any direct project references, but excludes any incoming dependencies from the main I've updated and somewhat cleaned up my old post with more detailed information on how to best reference resources from a typical addin style project here: .NET Core SDK Projects: Controlling Output Folders and Dependencies Output |
If desired, there is a further trick to this step. If you have many .dlls that need this treatment, and they are all below a singular file system node (subtree) such that there is a prevailing Instead, you can automatically apply the behavior to any/all of the (sub-suib-) In an appropriately prevailing Directory.Build.Props: <Project>
<ItemDefinitionGroup>
<ProjectReference>
<Private Condition="'$(OutputType)' == 'library'">false</Private>
</ProjectReference>
</ItemDefinitionGroup>
</Project> Intuitively enough, there's an extra level of nesting, which is the magic here: the As with the theory of this solution in general, we only want to affect Only the final executable host in a modular system should have to worry about and implement some policy for gathering the disparate parts needed for actual, runtime use, That policy should not be "regularly freeze the hard disk by wastefully reducing-down a gigatic union of 80% binary images which are byte-duplicates, since every sub-module has pointlessly hoarded duplicate copies for itself." Who cares about tracking overlapping usage between adjacent or unrelated plug-ins? It's a non-problem that can't affect anything; leave it to the host-build where it's comically trivial to just de-duplicate the entire set of all comers, for once and only. In fact, if the method described here is followed assiduously, there's not even any de-duping during the host build--it can just copy each sub-module's \bin directory into its own, and ideally there will be zero excess-copying and no .DLL file will ever be overwritten. I've done it this way for many years and the builds are obviously way faster, not to mention more reliable due to reduced overwriting collisions in general. A similar syntax works for subduing all <Project>
<ItemDefinitionGroup>
<PackageReference Condition="'$(OutputType)' != 'library'">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</ItemDefinitionGroup>
</Project> Oh, and |
I have a |
Is there still no good solution |
Steps to reproduce
I'm trying to build a project that has a Project Dependency to another project where the final output folder should not contain the original assembly and its depedencies. Essentially I need to use Copy Local: No behavior. This works for assembly references, but not for project references.
The options show in Visual Studio and in the project, but they seem to be ignored when the project is built.
Here's what the relevant project section I'm using looks like:
The project above is the main project of the application, and this project is an addin that runs in the context of that host application.
The project compiles fine, but the output folder of the addin project still gets all the host project references AND all of its dependencies. IOW, it pulls in the entire host application.
I've been working around this by using an explicit assembly reference instead of a project reference like this:
This works as expected, but this has build order problems where often compilation fails if the main project has not been compiled (even if explicitly setting the project dependencies in the solution file).
Other
This project is a multi-targeted WPF project to build both .NET Core 3.0 and for 4.6.2 and both the 3.0 and 4.6.2 build do the same thing.
This used to work just by
Copy Local: No
on the assembly reference added by a project reference in old style .csproj projects.Expected behavior
I'd like to see a Project Reference behave the same way as the Assembly Reference with
<Private>false</Private>
providing a compilation reference, but not actually copying the output into the build target folder.Actual behavior
Files are copied local even Copy Local: No
Environment data
OS info:
Windows 10
dotnet core SDK 3.0 Preview 5
.NET Core 3.0 WPF Project
The text was updated successfully, but these errors were encountered: