小编Nea*_*eal的帖子

netstandard 代码生成器 Microsoft.Data.SqlClient 抛出 FileNotFound System.Security.Principal.Windows,Version=4.1.1.0

我的 netstandard 2.0 代码生成器被核心 5.0 控制台应用程序引用。

csproj 看起来像这样

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
        <LangVersion>9.0</LangVersion>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Func" Version="0.2.2" />
        <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.8.0" PrivateAssets="all"/>
    </ItemGroup>
    
  <ItemGroup>
    <!-- Generator dependencies -->
    <PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.1" GeneratePathProperty="true" PrivateAssets="all" />
  </ItemGroup>

    <PropertyGroup>
        <GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
    </PropertyGroup>
    
    <Target Name="GetDependencyTargetPaths">
        <ItemGroup>
             <!--<TargetPathWithTargetPlatformMoniker Include="$(PKGSystem_Security_Principal_Windows)\runtimes\win\lib\netstandard1.3\System.Security.Principal.Windows.dll" IncludeRuntimeDependency="false" />-->
             <TargetPathWithTargetPlatformMoniker Include="$(PKGMicrosoft_Data_SqlClient)\runtimes\win\lib\netstandard2.0\Microsoft.Data.SqlClient.dll" IncludeRuntimeDependency="false" />
        </ItemGroup>
    </Target>

</Project>

Run Code Online (Sandbox Code Playgroud)

并引用 Microsoft.Data.SqlClient。

试图创建一个新的时,SqlConnection这样的

_dbConnection = new SqlConnection();           
_dbConnection.ConnectionString = @"validconnectionstring";
_dbConnection.Open();
Run Code Online (Sandbox Code Playgroud)

在连接打开时,会抛出一个带有消息的异常:

Could not …
Run Code Online (Sandbox Code Playgroud)

c# code-generation roslyn c#-9.0

5
推荐指数
1
解决办法
210
查看次数

标签 统计

c# ×1

c#-9.0 ×1

code-generation ×1

roslyn ×1