Add a third-party library to the Visual Studio Code project
Add a third-party .NET library by editing the
CSPROJ
project file.Prerequisites
Set Visual Studio Code as the default external code editor. See Set the default code editor.
- To add a third-party library to the Visual Studio Code project
- Copy the .NET assembly for the library to theProjectFiles/NetSolutionproject folder.
- From the main toolbar, selectOpen .NET Solution.The default external code editor opens.TIP: Rockwell Automation recommends usingVisual Studio®2022 orVisual Studio Codeas the default code editor. Some development assistance features may not be available when using a different code editor.
- In Visual Studio Code, open theCSPROJproject file.
- Add the following<Reference>element as a child of the<ItemGroup>element.<Reference Include="library"> <HintPath>path</HintPath> </Reference>
- library
- The library that you want to add. For example:MyLibrary
- path
- The path to the library from 1. For example:"MyLibrary.dll". Include the path to the library in the project directory to allow the project .NET solution to be compiled on different devices. In this way, the library is correctly referenced whenever acessing the project from other devices.
<ItemGroup> <Reference Include="MyLibrary"> <HintPath>MyLibrary.dll</HintPath> </Reference> <!-- The rest of the code --> </ItemGroup>If the library is located in a different folder than the one set by defaultProjectFiles/NetSolution, provide a path accordingly, for example:<Reference Include="MyLibrary"> <HintPath>../SampleFolder/MyLibrary.dll</HintPath> </Reference> - Save theCSPROJfile.
Provide Feedback