Compile .NET project with nuget packages Visual Studio

I want to create .DLL file out of dotnet project, but it uses some Nuget dependencies, which I would like to go to destination folder along with project's compiled DLL. How do I achieve that in Visual Studio?
8 Replies
Дядя Женя
Дядя ЖеняOP11mo ago
Basically I want Arch.dll to be compiled and all the referenced dlls it has to also be in the output folder
jcotton42
jcotton4211mo ago
how is this meant to be used? like, published to nuget? loaded as a plugin in another app? I think you just want dotnet publish though I don't remember if that works for library projects
Дядя Женя
Дядя ЖеняOP11mo ago
I want to use it in Unity as managed dll plugin Unity fails to load Arch.dll because it cannot find any of it's dependencies, which are nuget packages
jcotton42
jcotton4211mo ago
yeah, dotnet publish
Дядя Женя
Дядя ЖеняOP11mo ago
and Unity wants every dependency .dll to also be inside the folder
jcotton42
jcotton4211mo ago
or the publish option in Visual Studio if that shows up for library projects
Дядя Женя
Дядя ЖеняOP11mo ago
seems like it worked, thank you very much
Petris
Petris11mo ago
If you'd want their PDBs and XML docs to be copied too, I can send a bit of MSBuild code for that tomorrow
<Target Name="CopyReferenceFilesBuild" BeforeTargets="Build">
<ItemGroup>
<ReferenceFiles Include="%(Reference.RelativeDir)%(Reference.Filename).xml;%(Reference.RelativeDir)%(Reference.Filename).pdb" Exclude="%(Reference.RelativeDir)netstandard.xml" />
</ItemGroup>
<Message Text="Copying reference files to $(OutputPath)" Importance="High" />
<Copy SourceFiles="@(ReferenceFiles)" DestinationFolder="$(OutputPath)" Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')" />
</Target>

<Target Name="CopyReferenceFilesPublish" BeforeTargets="Publish">
<ItemGroup>
<ReferenceFiles Include="%(Reference.RelativeDir)%(Reference.Filename).xml;%(Reference.RelativeDir)%(Reference.Filename).pdb" Exclude="%(Reference.RelativeDir)netstandard.xml" />
</ItemGroup>
<Message Text="Copying reference files to $(PublishDir)" Importance="High" />
<Copy SourceFiles="@(ReferenceFiles)" DestinationFolder="$(PublishDir)" Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')" />
</Target>
<Target Name="CopyReferenceFilesBuild" BeforeTargets="Build">
<ItemGroup>
<ReferenceFiles Include="%(Reference.RelativeDir)%(Reference.Filename).xml;%(Reference.RelativeDir)%(Reference.Filename).pdb" Exclude="%(Reference.RelativeDir)netstandard.xml" />
</ItemGroup>
<Message Text="Copying reference files to $(OutputPath)" Importance="High" />
<Copy SourceFiles="@(ReferenceFiles)" DestinationFolder="$(OutputPath)" Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')" />
</Target>

<Target Name="CopyReferenceFilesPublish" BeforeTargets="Publish">
<ItemGroup>
<ReferenceFiles Include="%(Reference.RelativeDir)%(Reference.Filename).xml;%(Reference.RelativeDir)%(Reference.Filename).pdb" Exclude="%(Reference.RelativeDir)netstandard.xml" />
</ItemGroup>
<Message Text="Copying reference files to $(PublishDir)" Importance="High" />
<Copy SourceFiles="@(ReferenceFiles)" DestinationFolder="$(PublishDir)" Condition="Exists('%(RootDir)%(Directory)%(Filename)%(Extension)')" />
</Target>
if anybody wants it anyway
Want results from more Discord servers?
Add your server