.net - 如何在不调用每个项目的情况下让 dotnet build 选择正确的框架?

标签 .net bash ubuntu .net-core

所以情况是我试图在竹子上建立一个构建,它将构建这个包含许多项目的解决方案(它是一个共享库解决方案),每个项目都是一个 nuget 包。 Bamboo 目前在 Ubuntu 16.04 上运行。该解决方案包含库项目 (netstandard2.0) 和测试 (netcoreapp2.0)。每个库都针对 net461 和 netstandard2.0,因为它们在我们较新的 .net core 2.0 应用程序以及我们的 4.6.1 旧平台中都使用。

问题是如果我运行 dotnet build mysolution.sln然后cli尝试在net461中构建所有显然失败的东西(linux机器)。但是如果我运行 dotnet build mysolution.sln -f netstandard2.0然后测试无法构建,因为它们是 netcoreapp2.0。

我唯一能想到的就是写入构建脚本,该行使用正确的框架构建每个单独的项目,这对我来说似乎有点傻。

幸运的是,所有的测试项目都以 .Tests 为后缀。所以我觉得可能有办法做一些find /path -regex 'match-csproj-where-not-tests' and so forth...巫毒使这不那么烦人。我想知道那里是否有人可能知道一些我不知道的关于 dotnet cli 的事情,这可以帮助解决这个问题,甚至提供正则表达式解决方案。

TIA

最佳答案

当我在等待更好的选择时,我想出了这个:

#!/bin/bash

# build netstandard2.0
projects=($( find . -name '*.csproj' -print0 | xargs -0 ls | grep -P '(?![Tests])\w+\.csproj' ))
BUILDCODE=0
for proj in ${projects[@]}
do
    dotnet build $proj -f netstandard2.0
    BUILDCODE=$?
    if (($BUILDCODE != 0)); then
        echo "Failed to build $proj"
        break
    fi
done
(exit $BUILDCODE)

# build netcoreapp2.0
projects=($( find . -name '*.csproj' -print0 | xargs -0 ls | grep -P '\w+\.Tests\.csproj' ))
BUILDCODE=0
for proj in ${projects[@]}
do
    dotnet build $proj -f netcoreapp2.0
    BUILDCODE=$?
    if (($BUILDCODE != 0)); then
        echo "Failed to build $proj"
        break
    fi
done
(exit $BUILDCODE)

此搜索非 Test然后以 netstandard2.0 和 Test 为后缀的项目和构建后缀并将它们构建为 netcoreapp2.0。我会将它们作为两个不同的构建任务插入,以确保退出代码导致失败并且不要尝试继续。

dotnet test solution.sln 开始,我可能不得不做同样的事情来运行 xUnit 测试。由于库项目不包含测试而失败::eye_roll::

关于.net - 如何在不调用每个项目的情况下让 dotnet build 选择正确的框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50163391/

相关文章:

.net - 在 TestCleanup 中传递参数

.net - 哪些 .NET Framework 版本支持 Span<T> 的运行时增强功能?

linux - sed 命令删除找到的匹配项

c - 这是带有 IPv6 的 inet_pton 中的错误吗?

.net - 在 Model First 方法中使用时间戳属性进行 EF 并发处理

c# - ASP.NET Web 应用程序 - 在部署时,System.Speech.dll 对象未设置为对象的实例

linux - 改进我的备份 bash 脚本

linux - 通过 ssh 发送到主机的命令的返回状态

linux - ubuntu awk 如何获取最后一个用户和时间数据?

linux - 打印变量值大于特定数字的所有行