C
C#•3w ago
Kapara

Publish A Project That Reference To Another Project To Output DLL To `libs` Dir

Hello, I have a project X that compiles as library (DLL) with has a lot of nuget packages. This project used as utils for my other project, project A. Project A is a winExe project, self contained that I want to publish. Upon publish, it builds project X than project A. I want to put all the produced deps DLLs in project X into a directory named libs As for now, it does puts it there but the application cannot run and says that I need to install the dotnet runtime. (csprojs in comments)
18 Replies
Kapara
KaparaOP•3w ago
Project X csproj:
<!--============================Release Configuration============================-->
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PlatformTarget>AnyCPU</PlatformTarget>

<!--Disable debug symbols on release-->
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>

</PropertyGroup>

<!--============================Referenced Packages============================-->
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
...
</ItemGroup>
<!--============================Release Configuration============================-->
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PlatformTarget>AnyCPU</PlatformTarget>

<!--Disable debug symbols on release-->
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>

</PropertyGroup>

<!--============================Referenced Packages============================-->
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
...
</ItemGroup>
Project A csproj:
<!--Project References-->
<ItemGroup>
<ProjectReference Include="..\..\Project X\Project X\ProjectX.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>

<!--============================Release Configuration============================-->
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PlatformTarget>AnyCPU</PlatformTarget>

<!--Disable symbols on release-->
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>

<!--Publish as self contained-->
<SelfContained>True</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
</PropertyGroup>

<Target Name="MoveRunTimeLibraries" AfterTargets="Publish">
<ItemGroup>
<RuntimeLibraries Include="$(PublishDir)**\*.dll" />
</ItemGroup>
<Message Text="Moving runtime libraries to libraries directory"/>
<Move SourceFiles="@(RuntimeLibraries)" DestinationFolder="$(PublishDir)libs\"/>
</Target>
<!--Project References-->
<ItemGroup>
<ProjectReference Include="..\..\Project X\Project X\ProjectX.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>

<!--============================Release Configuration============================-->
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PlatformTarget>AnyCPU</PlatformTarget>

<!--Disable symbols on release-->
<DebugType>None</DebugType>
<DebugSymbols>False</DebugSymbols>

<!--Publish as self contained-->
<SelfContained>True</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
</PropertyGroup>

<Target Name="MoveRunTimeLibraries" AfterTargets="Publish">
<ItemGroup>
<RuntimeLibraries Include="$(PublishDir)**\*.dll" />
</ItemGroup>
<Message Text="Moving runtime libraries to libraries directory"/>
<Move SourceFiles="@(RuntimeLibraries)" DestinationFolder="$(PublishDir)libs\"/>
</Target>
FusedQyou
FusedQyou•3w ago
That sounds like a bad idea. Why do you want this? Just so I understand, you want to move the DLL files produced by project X into a libs folder in Project A? You already have a project reference, what is wrong with that?
FusedQyou
FusedQyou•3w ago
But if you really want this, you could probably create a Post-build event
Specify build events (C#) - Visual Studio (Windows)
Use build events in Visual Studio to specify commands that run before the build starts or after the build finishes for C# programs.
Kapara
KaparaOP•3w ago
@FusedQyou project X is a a library that has a packages in it that used by project A that references it. When publishing project A, the published folder is full of dotnet runtime dlls that looks massy
FusedQyou
FusedQyou•3w ago
Well it's not supposed to look good
Kapara
KaparaOP•3w ago
No description
FusedQyou
FusedQyou•3w ago
I think the better question is "how can I make sure that my project dependencies build into a different folder"
Kapara
KaparaOP•3w ago
Yeah.. It can be defined like that too mind that it's not only the project X, but the self contained dotnet runtime
FusedQyou
FusedQyou•3w ago
One thing my company does is just not reference dependencies and instead it builds everything and specify the build path to (in this case) go into Project A and into a libs subfolder But this sucks because you should just use proper dependencies
FusedQyou
FusedQyou•3w ago
A quick Google search gives me this: https://github.com/nulastudio/NetBeauty2
GitHub
GitHub - nulastudio/NetBeauty2: Move a .NET Framework/.NET Core app...
Move a .NET Framework/.NET Core app runtime components and dependencies into a sub-directory and make it beauty. - nulastudio/NetBeauty2
FusedQyou
FusedQyou•3w ago
Maybe you can use this as a Post-build event
Kapara
KaparaOP•3w ago
I am familiar with netbeauty, I thought maybe there's a native solution to it
FusedQyou
FusedQyou•3w ago
Doubt it
Kapara
KaparaOP•3w ago
maybe move all the dll to a libs folder and redirect the application to look for dependencies in libs
FusedQyou
FusedQyou•3w ago
This type of question is usually not really considered because you're not supposed to look at this anyway FWIW, I'd argue there's no folders at all and everything is inside the root
Kapara
KaparaOP•3w ago
Can't I alter the produced App.runtimeconfig.json to let it probe in lib path? yes, should I exlude it? there are like 10 of them 😄
Kapara
KaparaOP•3w ago
What about this solution? https://stackoverflow.com/a/72044506
Stack Overflow
Additional probing paths for .NET Core 3 migration
Short version of the question: Is there any way in .NET Core 3 to specify a local probing path, using the same rules as the <probing> element from app.config? additionalProbingPaths does not ...
Kapara
KaparaOP•3w ago
I'll check that. I can do something else and publish it as SingleFile but that the issue is that I cant work on the root dir file since every actions made for the root folder (create a file from the exe) results in the creation of it in %temp% Sounds good, I don't produce and pdb file in publish
var agentPath = Assembly.GetExecutingAssembly().Location;

var agentDirectory = Path.GetDirectoryName(agentPath);
var agentPath = Assembly.GetExecutingAssembly().Location;

var agentDirectory = Path.GetDirectoryName(agentPath);
Yeah I tried it, same issue For which on of them? .NET8 Oh I used CodeBase I ran it now and it seems to work What is the cons of selfcontained+singlefile beside changing the code where I access the root folder wdym by native dlls? It sound that the most stable option is to be self contain and have these long list of dlls in the root Yeah, the cons are one up on the pros on this one I just wanted to make my users to not to install the dotnet runtime anything else is an extra, also the tidy root folder
Want results from more Discord servers?
Add your server