编译后,我得到了一个错误:

/mnt/d/Users/Lev/adcm/18/ADCM_Connect/PilotWebApplication/PilotWebApplication.csproj : error NU1101: Unable to find package System.Windows. No packages exist with this id in source(s): nuget.org. 

我正在try 将XPS转换为PDF.为此,我通过NuGet下载了XpsToPdf库.其中有一个名为XpsConverter的类.以下是我的代码:

var _xpsDocument = new XpsDocument(stream, FileAccess.Read);

// Create an instance of PdfDocument
PdfDocument pdfDocument = new PdfDocument();
// Use XpsConverter to convert XPS to PDF
XpsConverter.Convert(_xpsDocument, pdfDocument, 0);
// Prepare a stream for writing PDF
var pdfStream = new MemoryStream();
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;
// Set response headers for PDF
Response.Headers.Add("Content-Type", "application/pdf");
var encodedFileName = System.Web.HttpUtility.UrlEncode(fileData.name);
Response.Headers.Add("Content-Disposition", $"attachment; filename=\"{System.IO.Path.ChangeExtension(encodedFileName, ".pdf")}\"");
// Return FileStreamResult with PDF
return new FileStreamResult(pdfStream, "application/pdf");

从错误中可以明显看出,缺少实现XpsDocument类的库.我发现System.Windows.Xps.Packaging中存在这样一个类,但这个包不能通过NuGet安装.你能告诉我我做错了什么吗?

以下是我当前的依赖:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Ascon.Pilot.Common" Version="20.1.0" />
    <PackageReference Include="Ascon.Pilot.DataClasses" Version="20.1.0" />
    <PackageReference Include="Ascon.Pilot.DataModifier" Version="20.1.0" />
    <PackageReference Include="Ascon.Pilot.SDK" Version="23.19.0" />
    <PackageReference Include="Ascon.Pilot.Server.Api" Version="23.19.0" />
    <PackageReference Include="Ascon.Pilot.Transport" Version="20.1.0" />
    <PackageReference Include="GhostscriptSharp" Version="1.3.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Analyzers" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.0" />
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.10.0" />
    <PackageReference Include="PdfSharp" Version="1.50.5147" /> 
    <PackageReference Include="Serilog" Version="3.0.1" />
    <PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
    <PackageReference Include="Syncfusion.Pdf.Net.Core" Version="17.3.0.14" />
    <PackageReference Include="Syncfusion.XpsToPdfConverter.Net.Core" Version="17.3.0.14" /> 
    <!-- <PackageReference Include="System.Security.Claims" Version="4.3.0" />-->
    <PackageReference Include="XpsToPdf" Version="1.0.5" /> 
    <PackageReference Include="System.Windows" Version="8.0.0" />
  </ItemGroup>

</Project>

我应该做什么调整来解决这个问题?

推荐答案

supported frameworks by XpsToPdf nuget:

Product Versions
.NET ... net6.0-windows ...
.NET Framework ...

因此,它需要net6.0-windows个目标框架,这是net6.0个具有Windows特定功能的目标框架,仅仅net6.0个是不够的:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    ...

Csharp相关问答推荐

Rx.Net -当关闭序列被触发时如何聚合消息并发出中间输出?

在包含空项的列表上使用具有断言T的摘要表

Polly v8—使用PredicateBuilder重试特定的状态代码

为什么SignalR在每个Blazor服务器应用程序启动时最多启动8个服务器?

Blazor EventCallback<;MyType<;T>;>;

如何在C#中从正则表达式中匹配一些数字但排除一些常量(也是数字)

Blazor在FluentButton onClick事件上设置参数

如何通过寻找向量长度来优化两个循环?

使用带有参数和曲面的注入失败(&Q;)

用于管理System.Text.Json中的多态反序列化的自定义TypeInfoResolver

Selify只更改第一个下拉菜单,然后忽略REST-C#

在C#中过滤Excel文件

如何允许数组接受多个类型?

为什么我的伺服电机不动,下面的代码?

CRL已过期,但ChainStatus告诉我RevocationStatus未知

如何实现有条件的自定义Json转换器隐藏属性

try 创建一个C#程序,该程序使用自动实现的属性、覆盖ToString()并使用子类

如何在Xamarin.Forms中检索PanGesture事件的位置?

我是否以错误的方式使用了异步延迟初始化?

我如何为我的Blazor应用程序构建一个动态教程标注?