Xamarin跨平台新手求助:无法安装ITextSharp包(VS2017 V15.6.6)
Hey there, let's work through this package installation problem step by step—since you're new to Xamarin, we'll start with the basics and move to project-specific fixes.
First: Fix Visual Studio & NuGet Core Issues
Since you can't install any packages, the problem likely starts with your NuGet setup or VS installation:
- Update NuGet Package Manager: Your VS 2017 version is a bit dated, and outdated NuGet is a top cause of installation failures. Head to
Tools > Extensions and Updates > Updates > Visual Studio Marketplace > NuGet Package Managerand install any available updates. Restart VS after this. - Clear NuGet Cache: Corrupted cache files often break package installs. Go to
Tools > Options > NuGet Package Manager > Generaland clickClear All NuGet Cache(s). Restart VS once done. - Verify Package Sources: Make sure the official NuGet gallery is enabled. Go to
Tools > Options > NuGet Package Manager > Package Sources—check thatnuget.orgis listed and checked. If it's missing, add it with the URLhttps://api.nuget.org/v3/index.json.
Next: Specific Fixes for iTextSharp (Plus a Critical Note)
Before diving in: iTextSharp is no longer actively maintained, and it can have compatibility hiccups with modern Xamarin projects. The official, supported successor is iText 7, which works better with .NET and Xamarin. But if you specifically need iTextSharp, here's what to do:
- Check Your Project's Target Framework: iTextSharp 5.5.13.2 (the last stable release) supports .NET Framework 2.0+, Xamarin.iOS, and Xamarin.Android. Double-check your project's target framework in the project properties to ensure it matches.
- Install via Package Manager Console: If the GUI package installer fails, use the console for more control and clearer error messages. Open
Tools > NuGet Package Manager > Package Manager Consoleand run:
If this fails, the error message will tell you exactly what's blocking the install (like dependency conflicts).Install-Package iTextSharp -Version 5.5.13.2 - Resolve Dependency Conflicts: If you get dependency errors, use the
Get-Packagecommand in the Package Manager Console to list all installed packages. Look for packages that require conflicting framework versions or clash with iTextSharp's requirements.
Then: Rule Out Project Corruption
If even simple packages won't install in your project, it might be corrupted. Try these steps:
- Test a Blank Project: Create a new, empty Xamarin.Forms or native Xamarin project, then try installing a basic package like
Newtonsoft.Json. If this works, your original project is likely damaged. - Repair the Original Project:
- Delete the
packagesfolder in your project directory. - Delete the hidden
.suofile in your solution folder (you'll need to show hidden files in File Explorer). - Reopen the solution, right-click the solution in Solution Explorer, and select
Restore NuGet Packages.
- Delete the
Last Resort: Repair Visual Studio
If even new projects can't install packages, your VS 2017 installation is probably corrupted. Go to Control Panel > Programs > Programs and Features, find Microsoft Visual Studio 2017, click Change > Repair. This will fix missing or broken components.
Alternative: Switch to iText 7
If you're open to it, iText 7 is the modern, supported replacement. It's more compatible with Xamarin and gets regular updates. Install it via the Package Manager Console with:
Install-Package iTextSharp.LGPLv2.Core -Version 1.7.10
内容的提问来源于stack exchange,提问作者Subrata Mitra

