我想在Visual Studio Code中添加对自定义C#程序集的引用,比如
"../libs/mylib.dll"
该如何添加这个依赖项呢?
我试图添加该依赖项的路径,但由于路径错误而无法编译 :)
"dependencies": {
"myassembly" : "../libs/Common.dll"
},
或者"dependencies": {
"log4net" : { "assembly":"../libs/log4net.dll" }
},
我想在Visual Studio Code中添加对自定义C#程序集的引用,比如
"../libs/mylib.dll"
该如何添加这个依赖项呢?
我试图添加该依赖项的路径,但由于路径错误而无法编译 :)
"dependencies": {
"myassembly" : "../libs/Common.dll"
},
或者"dependencies": {
"log4net" : { "assembly":"../libs/log4net.dll" }
},
更简单的做法,只需添加以下内容:
1)修改myproject.csproj文件
<ItemGroup>
<Reference Include="DllComunVb2008">
<HintPath>..\Dlls\DllComunVb2008.dll</HintPath>
</Reference>
</ItemGroup>
2) 添加你将要使用的库的 using
。例如:using Dllcomun;
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<OutputPath>bin\Debug\</OutputPath>
为了
<OutputPath>libs</OutputPath>
...
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
...
</ItemGroup>
...
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{75278D05-4850-4282-8AB4-3643A9E799FF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>libs</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="myassembly.cs" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
我刚看到这个问题,所以想要添加一些有用的链接,供大家通常使用CLI。看起来你仍然需要手动添加一个dll文件...
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference
如果您正在构建库并将其作为解决方案的一部分添加,则可以使用CLI在需要时添加引用,请参见以下链接。你也可以自己打包成一个包,但是除非你有自己的源,否则你需要进行一些类似的自定义.csproj
更改。