我终于找到了一种在 Visual Studio 代码中引用任何 .net 程序集的方法。
首先要注意:我只需要智能感知的 vscode。我不会在 vscode /.netcore 中编译程序集。
完成编码后,我将使用命令行工具生成我的程序集。
这是我的解决方案:
使用 Visual Studio(不是代码)创建常规 .net 类库
这将创建一个 myproject.csproj 文件(可以由 vscode 读取)。
或者使用我在帖子底部的 test.csproj 文件。
为引用的程序集创建一个文件夹。我刚刚在顶级目录中创建了一个 libs 目录。
关闭 vs 并使用 vscode 打开文件夹。
修改 *.csproj 文件如下:
注意:我们已经在调试模式下创建了项目,所以我们可以删除 release-property-group:
4.2。删除 Release-PropertyGroup(您不必这样做,但您不需要它)
<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>
4.3。修改bin-output-path到libs-directory
来自
<OutputPath>bin\Debug\</OutputPath>
到
<OutputPath>libs</OutputPath>
4.4。将您的引用 .net 程序集(外部或自定义)放在 libs 目录中,并像这样引用它们:
...
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<SpecificVersion>False</SpecificVersion>
<HintPath>log4net.dll</HintPath>
</Reference>
...
</ItemGroup>
...
这是参考 log4net.dll 的完整 *.csproj 文件。
<?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>