In reference to Reference c# class library in my Azure Function I would like to ask the same question how to achieve this
- with a precompiled C# Azure function
- with any kind of .dll (that is provided as such, thus not a NuGet)
- within VS Code
AFAIK this is not documented
Add a folder like MyAssemblies containing our dlls under function app folder.
Then add references in functionappname.csproj.
<ItemGroup>
<Reference Include="MyCustomDll">
<HintPath>./MyAssemblies/MyCustomDll.dll</HintPath>
</Reference>
</ItemGroup>
Related
I am probably being a bit stupid ;) but I have a Problem in my Azure Pipline.
I used the the SignalR Library from AspNetCore to build a Hub. Since .NetCore3.0, the SignalR is automatically devliverd with AspNetCore.
That my Hub Class public class UrgentAcknowledgedHub : Hub {} did know where the Library (dll) is, i had to add following code to my .csproj File.
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.SignalR.Core">
<HintPath>..\..\..\..\..\Program Files\dotnet\shared\Microsoft.AspNetCore.App\6.0.8\Microsoft.AspNetCore.SignalR.Core.dll</HintPath>
</Reference>
</ItemGroup>
I can run this code local without any problem, but when the Azure pipline run this code, I got following Error and it crashes:
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.AspNetCore.SignalR.Core". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
I totally understanding that it can't find the SignalR Referenc anymore because it is hardcoded. Is there any way to not hardcode it?
I think i got the Answer. To use the SignalR from the .Net6 Framework, I have to add the following FrameworkReference in my .csproj File.
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>
I have a problem with a C++ library that I have.
This C++ library includes a Library file (abc.lib) but I also need this library file copied to the output folder.
The C++ library is then used in a C# application and I need the library file to be automatically included in the c# application when it is referenced.
I can't seem to find a way to copy the library file to the output folder and use the library in the c++ app. I do not want to use a post build event as this won't then get the library file copied to the c# application.
<ItemGroup>
<Library Include="abc.lib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Library>
</ItemGroup>
The CopyToOutputDirectory directive does not work above (I am not sure it is even supported)
Any thoughts?
I know you can set the Item Type property to Copy File, but then it is not treated as a library as the app does not compile.
My problem is rather simple, we have a solution mixing C++ and C#, our C++ project are referring to their dependencies (external libraries) with property sheet attached with the Property Manager window.
As the C# project are not shown in the property manager, i still tried to add the .props to the project but can't find a way to make it work, the defined Dll in the .props are still unknown to the project.
Our props are rather simple.
<ItemDefinitionGroup>
<Link>
<AdditionalLibraryDirectories>$(External_Repository)\Win64\Static</AdditionalLibraryDirectories>
<AdditionalDependencies>LibA.dll;LibB.dll;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
The dll are quit heavy, we must save on distant repository and reference them And our architecture help us switch version easily.
Folder :
- Version1.1
-LibA.dll
- ...
- Version2.0
- LibA.dll
- ...
As such if there is a way to make it work without modifying the .VCSPROJ and solely using .props, it'll be wonderful.
How can i make it work? thanks you in advance.
Thanks to C# reference in .props file
I found my answer !
<ItemGroup>
<Reference Include="LibA">
<HintPath>$(External_Repository)\LibA.dll</HintPath>
</Reference>
Don't forget to make sure your props is well included.
I have an .NET Standard project where I implemented a module for an ASP.NET Core CMS framework. Currently, it uses the CMS framework libraries coming from NuGet packages. If I grab the source code of the CMS framework from GitHub and add my module to its solution and replace the package references to the actual project references it will work fine.
My goal is to make it work without updating the references in the csproj file so if the project is added to the full source code solution then use the project references, otherwise use the NuGet package references.
So let's say the .NET Standard project is called 'ModuleA'. It has a package reference to 'ModuleB':
<ItemGroup>
<PackageReference Include="ModuleB" Version="1.0.0" />
</ItemGroup>
When I want to use ModuleA in a solution where ModuleB is accessible then I use project reference to it:
<ItemGroup>
<ProjectReference Include="..\..\ModuleB\ModuleB.csproj" />
</ItemGroup>
I'd like to include both of them in the .csproj file somehow and make it to use the proper references on build (e.g. based on some conditions like project exists?).
If both are added to the csproj then the build will fail (e.g. 'Unable to find project ...ModuleB.csproj. Check that the project reference is valid and that project file exists.').
You could do that probably dynamically, but I think it's not really transparant how that would work.
I would recommend to add a configuration, e.g. in my example "Local-Debug" and use conditions in your csproj.
Example
Creating the configuration:
And in your csproj you could do this:
<ItemGroup>
<ProjectReference Condition="'$(Configuration)' == 'Local-Debug'" Include="otherProject.csproj" />
<PackageReference Condition="'$(Configuration)' != 'Local-Debug'" Include="otherProjectPackage" Version="2.4.1" />
</ItemGroup>
Your dependencies must be statically known and resolve-able at build-time. See #Julian's answer for a good config-driven build-time solution.
As a run-time solution: You can dynamically load your references at run-time. This way, you can search for the DLL you need in the working directory of your app and if you don't find it there, then download it (from Nuget or elsewhere), either as a binary that you can directly load, or as a source that you can build; and then load that library dynamically.
Here's how you can load an assembly dynamically (at run-time): https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.loadfrom?view=netframework-4.8
And this question: Loading library dynamically
Coding against a dynamically loaded assembly has its own quirks; you will need clear interface definitions for the referenced library, or else, you'll find yourself dealing with a lot of reflection and dynamics.
Is it possible to programmatically replace DLL refs with Project refs for project dependencies in Visual Studio C#/VB.NET solution?
BACKGROUND:
I'm working with some legacy code where dependencies for each project are mostly referenced as compiled DLLs instead of including project reference from corresponding project in solution or even worse - referenced straight from GAC!
Right now I have to manually remove each DLL reference and replace it with project reference from VS UI for each solution out of dozens projects.
Editing the project/solution XML .csproj/.sln files is not straightforward due to GUIDs:
<!--typical DLL reference-->
<ItemGroup>
<Reference Include="MyDLL, Version=2.0.1.0, Culture=neutral, PublicKeyToken=1b6d1e0267e1acba, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>...\MyDLL.dll</HintPath>
</Reference>
</ItemGroup>
<!--typical Project reference-->
<ItemGroup>
<ProjectReference Include="..\MyDLL\MyDLL.csproj">
<Project>{3cc27830-3d6b-4071-85e5-5a4006f11142}</Project>
<Name>MyDLL</Name>
</ProjectReference>
</ItemGroup>
Use this plug-in .. It might help on your problem
https://visualstudiogallery.msdn.microsoft.com/056617a4-da39-4d7b-8ecf-933009d9b721
It has description below
Switches references from file to projects (and vice versa) references
when adding projects. References are reverted when the project is
removed.
usage:
You are developing project A which has a file reference to assembly
"b.dll". At some point you need to make changes to "b.dll" . So you
add project "B" to the solution. The ReferenceSwitcher will detect
that project B produces an assembly called "b.dll" and ask if you want
to switch all references from "b.dll" to project B.
Then at some point later, you no longer need project B in your
solution, so you remove project B. The reference switcher will
detected that references to B used to point to "b.dll" and ask you if
you would like to update them.
More info here:
http://markkemper1.blogspot.com/2011/09/project-to-file-reference-switcher-for.html
Edit:
there are lots of plug-in available to solve your purpose check them out
https://visualstudiogallery.msdn.microsoft.com/197d94f6-6276-471d-853d-a5a322ccb08c
OR search them all
https://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=SearchText&f%5B0%5D.Value=reference&pageIndex=2