Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reference another project (tool) but not make it available in referencing project#10440

Unanswered
vladd asked this question inQ&A
Discussion options

I've got the following setup:

Solution    ToolProject    LibraryProject    MainAppProject

LibraryProject is a .NET library referenced by .NET MainAppProject.
ToolProject is a .NET project too, it compiles to an executable which is sometimes run by the LibraryProject (I cannot link against ToolProject because it needs a different bitness).

Now, I want the output of ToolProject be available for the MainApp (as a transitive dependency of LibraryProject).

For it, I tried using

<ProjectReference Include="..\ToolProject.csproj">    <ReferenceOutputAssembly>False</ReferenceOutputAssembly></ProjectReference>

in LibraryProject.csproj, but this way only Tool.exe is copied to the target folder, not the other files.

I tried using

<ProjectReference Include="..\ToolProject.csproj">    <ReferenceOutputAssembly>True</ReferenceOutputAssembly>    <OutputItemType>Content</OutputItemType>    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></ProjectReference>

This achieves the job, but it has an unfortunate effect that the classes from ToolProject become available in the LibraryProject, which is very misleading and leads to conflicts.

The question: is it possible to reference the ToolProject so that it will be used as a dependency from the project point of view (compile order, copying to the output, etc.), but will not be visible in the LibraryProject's source code?

You must be logged in to vote

Replies: 2 comments 13 replies

Comment options

This isn't very easy right now. The main tracking bug isdotnet/runtime#53834.

You must be logged in to vote
8 replies
@vladd
Comment options

@JanKrivanek This seems pretty close. WithDisableTransitiveProjectReferences I can disallow references to the downstream projects (in my case, to the libraries which are used by ToolProject). But what I actually need is disabling references to the ToolProject itself, too.

@JanKrivanek
Comment options

@vladd - If I understand you correctly - you are interested only in copying the build outputs, without exposing the reference public surface to other project(s) in the build - is that correct? There is no short-cut reference metadata support for those requirements. You'd need to write a custom target yourself (that copies the content of the OutputPath after build to the directory of interest). But perhaps theArtifacts output layout might help you achieve what you are looking for?

@vladd
Comment options

@JanKrivanek

you are interested only in copying the build outputs, without exposing the reference public surface to other project(s) in the build - is that correct?

Exactly, this is my goal.

You'd need to write a custom target yourself (that copies the content of the OutputPath after build to the directory of interest).

Well, this is perhaps going to be tricky, as I would need to specify the build order dependency somehow, right?

@JanKrivanek
Comment options

You should still be able to use theReferenceOutputAssembly to guarantee the build order. The deps copying would however be on you.

But please try to first have a look onArtifacts output layout to see if it can help you achive your goal.

@Nirmal4G
Comment options

See, that's the thing..., in most Plug-in or tools based project structure, we don't need the reference but want the build order and the copying of dependencies.

I struggled with this problem quite a lot and IMHO, settingReferenceOutputAssembly=False should ensure build order. TheProjectReference should also respectPack,Publish andCopyToOutputDirectory.

Comment options

This isn't possible withProjectReference right now but you can specify project dependencies within the solution through the Solution Properties dialog in Visual Studio. Remove theProjectReference before setting the Project dependencies in the solution.

After that, MSBuild/VisualStudio will always build in the expected order without referencing the tool project.

You must be logged in to vote
5 replies
@vladd
Comment options

Unfortunately, build order seems to be not enough, because I need the project output to be copied to the referencing project’s output folder.

@Nirmal4G
Comment options

Build order ensures that the dependencies will always be built first and then you can gather the build outputs and copy them manually into the referencing project.

Just like here:CommunityToolkit/dotnet#220

See theDynamically Pack... commit. Especially the...GetBuildOutputs.targets file which shows how to gather the outputs and the...Packaging.targets file which shows how to use it.

@vladd
Comment options

Well, it's not that easy, since the referencing project may be a library as well, so we need it to be a transitive dependency for copying. Sorry for being unclear in my previous answer.

@vladd
Comment options

The customary<ProjectReference> means from user's point of view 2 things:

  • the public classes from the referenced project are available in the referencing project
  • the output files of the referenced project appear in the output folder of the executable project which is
    • either referencing project itself if it's executable;
    • or, if the referencing project is a library, in every executable project referencing (maybe indirectly) this library.

My need is to remove the first bullet while keeping the second (because the tool will be started by the referencing library as a process). (I need the referenced project to be a separate tool, because it has different bitness.)

@Nirmal4G
Comment options

Exactly what I was trying to solve in my own projects. I don't want to reference the files in Code but want them in output/publish directory.

In my own projects, I never went beyond 2 levels of transitive references, so, I can't confidently say that this might work beyond that but it's a starting point.

You can look at thebinlog to see where and how the transitive references flow and then hook these targets at appropriate places and add the transitive Items either inBuildOutputPerTarget orBuildOutput items inside theGetBuildOutput... targets. This will get you the entire output including transitive references.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
4 participants
@vladd@rainersigwald@JanKrivanek@Nirmal4G

[8]ページ先頭

©2009-2025 Movatter.jp