【问题标题】:Newly created Cross-Platform Xamarin.Forms project fails to build after updating NuGet Packages更新 NuGet 包后新创建的跨平台 Xamarin.Forms 项目无法构建
【发布时间】:2019-06-16 07:25:44
【问题描述】:

我正在尝试在 Visual Studio Community 2017(版本 15.9.5)中使用 Xamarin.forms 创建一个跨平台移动应用。

创建项目后,我更新了 NuGet 包并收到 3 个错误和 1 个警告(注意:我根本没有编写任何代码)。

您可以在下面找到我所做的详细过程和详细的错误消息。

我单击文件 > 新建 > 项目 > Visual C# > 跨平台 > 移动应用程序 (Xamarin.Forms)。

我命名我的项目并提示我选择一个模板,我选择“空白应用程序”。

对于平台,我选择所有 3 个(iOS、Android、UWP),作为代码共享策略,我选择“共享项目”。

创建项目后,我打开 NuGet 包管理器并更新我的所有包,在这里您可以看到它们的最新版本。 更新软件包后,我收到 7 个警告和 1 个错误。我清理并重建了解决方案,但我不断收到这些错误和警告,尽管它们有时会在我没有更改任何内容的情况下更改。

我可能会看到 7 个警告并且没有错误,关闭项目,再次打开它,重新构建并得到 3 个错误和 1 个警告。

这里是目前的错误列表:

这是完整的输出:

1>------ 重建所有开始:项目:Bencivenga_Gioele_Bengalino.Android,配置:调试任何 CPU ------ 2>-------- 跳过全部重建:项目:Bencivenga_Gioele_Bengalino.iOS,配置:调试 iPhone ------ 2>未选择为此解决方案配置构建项目 3>------重建所有开始:项目:Bencivenga_Gioele_Bengalino.UWP,配置:调试x86 ------ 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(3064,2): 错误:指定的路径、文件名或两者都是太长。完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符。 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1327,2): error XA4303: Error extracting resources from "C:\Users \gioel.nuget\packages\xamarin.android.support.compat\28.0.0.1\lib\monoandroid81\Xamarin.Android.Support.Compat.dll": System.IO.PathTooLongException: 指定的路径、文件名或两者都是太长。完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符。 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1327,2): 错误 XA4303: 在 System.IO.LongPathHelper.Normalize( String path, UInt32 maxPathLength, Boolean checkInvalidCharacters, Boolean expandShortPaths) 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1327,2): 错误 XA4303: 在 System.IO.Path.NewNormalizePath( String path, Int32 maxPathLength, Boolean expandShortPaths) 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1327,2): 错误 XA4303: 在 System.IO.Path.NormalizePath(字符串路径、布尔型 fullCheck、Int32 maxPathLength、布尔型 expandShortPaths) 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1327,2): 错误 XA4303: 在 System.IO.Path.GetFullPathInternal(字符串路径) 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1327,2):错误 XA4303:在 Xamarin.Android.Tools.Files。 ExtractAll(ZipArchive zip,字符串目标,Action2 progressCallback, Func2 modifyCallback,Func2 deleteCallback, Boolean forceUpdate) 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1327,2): error XA4303: at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection1 jars,ICollection1 resolvedResourceDirectories, ICollection1 resolvedAssetDirectories,ICollection`1 resolvedEnvironments) 3> Bencivenga_Gioele_Bengalino.UWP -> C:\Users\gioel\Documents\Repositories\GitHub\BengalinoUWP\Bencivenga_Gioele_BengalinoApp\Bencivenga_Gioele_Bengalino\Bencivenga_Gioele_Bengalino\Bencivenga_Gioele_Bengalino.UWP\bin\x86\Debug\Bencivenga_Gio 3>C:\Users\gioel.nuget\packages\microsoft.net.uwpcoreruntimesdk\2.1.2\tools\CoreRuntime\Microsoft.Net.CoreRuntime.targets(195,9):错误:框架资源提取失败。指定的路径、文件名或两者都太长。完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符。 ==========全部重建:0成功,2失败,1跳过==========

我在网上搜索了一个解决方案,发现了一些旧线程,他们建议使用 LongPathTool 来解决最多 260 个字符的问题,但他们的说明是“只需安装它就可以工作”,而且这样做是' t让任何事情对我有用。

感谢您阅读该问题,如果您给我有关此问题的任何想法或建议,则更加感谢。欢迎询问更多详情。

【问题讨论】:

    标签: visual-studio xamarin xamarin.forms cross-platform


    【解决方案1】:

    将您的项目移动到C:// 的根目录下,这通常可以解决该特定错误。

    尝试在C:\Users\ 中创建一个名为 XamarinProjects 的文件夹,并将您的解决方案放在那里。

    经过一番挖掘,我发现了这个:

    <PropertyGroup>
        <UseShortFileNames>True</UseShortFileNames>
    </PropertyGroup>
    

    如果设置此标志不能修复 PathTooLongException 错误,另一种方法是通过在项目 .csproj 文件中设置 IntermediateOutputPath 来为解决方案中的项目指定一个公共中间输出根。尝试使用相对较短的路径。例如:

    <PropertyGroup>
        <IntermediateOutputPath>C:\Projects\MyApp</IntermediateOutputPath>
    </PropertyGroup>
    

    来自Official Documentation

    【讨论】:

    • 这真的是唯一的方法吗?我在其他地方看到过它,但我更愿意将我的项目保留在原处
    • 当我使用 Windows 时,这是我做过的最好的解决方法。
    • 感谢您的更新,您能解释一下我应该在哪里设置该标志吗?我应该把它写在我共享项目的 MainWindow 的 XAML 代码中吗?
    • 忘记看你链接的官方文档了,我会尝试反馈的,在此期间再次感谢您的帮助。
    • 不走运,两种方法都试过了,但错误并没有消失。由于现在更改文件夹有效,因此我将接受此解决方法。感谢您向我指出官方解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 2017-12-19
    • 2018-03-07
    • 1970-01-01
    相关资源
    最近更新 更多