在Visual Studio代码中我只想添加一个引用 一个自定义的c#程序集,如
“../库/中是指mylib.dll”
如何添加此依赖项?
我试图添加依赖的路径但是无法编译,因为它的错误:)
"dependencies": {
"myassembly" : "../libs/Common.dll"
},
或
"dependencies": {
"log4net" : { "assembly":"../libs/log4net.dll" }
},
答案 0 :(得分:11)
更简单,只需添加以下内容:
1)修改myproject.csproj文件
<ItemGroup>
<Reference Include="DllComunVb2008">
<HintPath>..\Dlls\DllComunVb2008.dll</HintPath>
</Reference>
</ItemGroup>
2)添加您要使用的库的using
。示例:using Dllcomun;
答案 1 :(得分:5)
我终于找到了一种在visual studio代码中引用任何.net程序集的方法。
首先要注意:我只需要智能感知的vscode。我不会在vscode /.netcore中编译程序集。 当我完成编码时,我将使用命令行工具生成我的程序集。
这是我的解决方案:
使用Visual Studio(非代码)创建常规.net类库 这将创建一个myproject.csproj文件(可由vscode读取)。 或使用帖子底部的test.csproj文件。
为引用的程序集创建一个文件夹。我刚在顶级目录中创建了一个 libs 目录。
关闭 vs 并使用 vscode 打开文件夹。
修改* .csproj文件,如下所示:
注意:我们已经在调试模式下创建了项目,因此我们可以删除release-property-group:
4.2。删除发布 - PropertyGroup (您不必,但您不需要它)
var data = [5, 2, 7, 9, 2, 3, 8, 4];
// end holds the position of the last unsorted number
var end = data.length - 1;
// start holds the position of the first unsorted number
var start = 0;
// position is the current index of the number which is of interest
var position = start;
// while the two sorted halves have not met
while (start < end) {
var subject = data[position];
if (subject % 2 === 1) {
// it's odd, it's already in the correct half of the array
// so move to the next number, and increase start, marking this
// number as sorted
position++;
start++;
} else {
// it's even, move it to the even sorted section. The means that
// the number in "position" has not been looked at yet, so do not
// increase "position", but there's an extra sorted number at the
// end, so decrease "end"
var temp = data[end];
data[end] = subject;
data[position] = temp;
end--;
}
}
console.log(data);
4.3。修改bin-output-path到libs-directory
这
<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>
4.4。将您的引用.net程序集(外部或自定义)放在libs目录中,并引用它们:
<OutputPath>libs</OutputPath>
这是完整的* .csproj文件,引用了log4net.dll。
...
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
...
</ItemGroup>
...
答案 2 :(得分:0)
我用dotnet创建一个项目,然后用Visual Studio 2019打开它。然后单击项目,添加引用,浏览到Dll,然后保存项目(保存解决方案,以防您想再次使用文件打开它) 现在用vscode打开它。