【问题标题】:Dotnet build is returning different resultsDotnet 构建返回不同的结果
【发布时间】:2021-07-05 07:40:14
【问题描述】:

当我在生成新的统一脚本后尝试构建我的 *.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。

【问题讨论】:

  • 根据我的经验,无论您使用什么代码编辑器,Unity Editor 都会自行构建项目。即使你删除了所有的 csproj 文件,Unity 也可以为自己构建项目。例如,当您在 VS 中打开某些脚本时,它将再次创建所有丢失的 csproj 文件,您可以点击 VS(或我想是 Rider)中的构建按钮,但它仅适用于您拥有的 c# 脚本,然后当您来完成一些更改并在您的代码编辑器中构建后返回 Unity 编辑器 Unity 将始终从其一侧重新构建(考虑到许多其他事情)
  • @kolodi 抱歉,我不够精确。我需要创建一个自动构建,但我需要从构建中排除一些 csproj。

标签: .net unity3d build


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    • 2012-11-30
    • 2019-06-03
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多