首页 > 解决方案 > Dotnet 构建返回不同的结果

问题描述

当我在生成新的统一脚本后尝试构建我的 *.csproj 时,我遇到了一个奇怪的问题。让我解释一下工作流程。

首先,我要从 Unity 主目录中删除所有旧的 *.csproj 文件。然后我使用以下脚本来生成全新的项目文件

var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
    foreach (var type in assembly.GetTypes())
    {
        if (type.FullName == "Packages.Rider.Editor.ProjectGeneration.ProjectGeneration")
        {
            var projectGeneration = Activator.CreateInstance(type);
            type.GetMethod("Sync").Invoke(projectGeneration,null);
            EditorApplication.Exit(0);
        }
    }
}

接下来,我尝试通过 cmd 命令构建每个 *.csproj:dotnet build C:\Projects\xxx\xxx\*.csproj --force --no-restore

这就是奇怪的事情发生的地方。该命令的第一次运行总是返回许多错误和警告,但它们的实际数量每次都不同。第二次是减少它们的数量,第三次运行通常不会导致错误,只是出现一些警告。

我知道,我没有得到相关的结果,因为应该出现的警告在几次运行后没有被指出。

以下是一些出现的错误

        CSC : error CS0006: Metadata file 'C:\Projects\xxx\xxx\Temp\Bin\Debug\ARFoundation.dll' could not be found [C:\Projects\xxx\xxx\xxx.csproj]
        CSC : error CS0006: Metadata file 'C:\Projects\xxx\xxx\Temp\Bin\Debug\xxx_OclussionCulling.dll' could not be found [C:\Projects\xxx\xxx\xxx.csproj]
        CSC : error CS0006: Metadata file 'C:\Projects\xxx\xxx\Temp\Bin\Debug\QuickGraph.dll' could not be found [C:\Projects\xxx\xxx\xxx.csproj]
        CSC : error CS0006: Metadata file 'C:\Projects\xxx\xxx\Temp\Bin\Debug\Unity.XR.Interaction.Toolkit.dll' could not be found [C:\Projects\xxx\xxx\xxx.csproj]

我的问题是为什么会发生这种情况,我该如何解决?主要目标是自动化构建,但我必须单独构建每个 *.csproj,因为我需要从构建中排除一些 *.csproj。

标签: .netunity3dbuild

解决方案


好的,所以我前段时间找到了解决方案。我的问题是,我没有以正确的顺序构建项目,这在这种情况下至关重要。

项目构建的有效顺序保存在主 *.sln 文件中。当您想要手动构建 *.csproj 文件时,您必须注意正确的顺序。


推荐阅读