在命令行(或项目文件以外的其他地方)指定对 xbuild 的引用

Specifing references for xbuild on the command line (or some other place than the project file)

我有一个 xamarin-forms PCL 解决方案,其中还包含一个 NUnit 项目,该项目仅测试非 GUI 方面。

我在windows下开发。

现在我想 运行 在我的 CI 服务器上对 linux(使用单声道)进行 NUnit 测试。

为此,我需要编译 PCL 项目和 NUnit 项目(并且 而不是 android 和 iOS)。

当 运行在 NUnit 项目中使用 xbuild 时,它告诉我:

AppTests.cs(1,7): error CS0246: The type or namespace name `MY_App' could not be found. Are you missing an assembly reference?

(MY_App 是 PCL 项目的名称)。 现在我可以添加:

<Reference Include="My_App">
  <HintPath>..\My-App\MY_App\bin\Release\MY_App.dll</HintPath>
</Reference>

而且有效!

我的问题:除了为 linux 调整项目文件之外,还有其他方法吗?这些项目文件的主要用途是从 visual studio 开始使用。我能否以某种方式在命令行或额外文件中指定引用?

不是添加硬编码程序集(通过 <Reference> 元素),而是为您的 MY_App.csproj 添加一个基于 项目 的引用到您的 NUnit基于项目。这可以通过 IDE(Visual Studio、Xamarin Studio、....)或通过手动编辑 .csproj 文件来完成。

您最终会得到一个 ProjectReference,看起来像:

<ProjectReference Include="..\RealmLoginKitTest\RealmLoginKitTest.csproj">
  <Project>{6524A097-D064-4933-987F-76EB19AF3F57}</Project>
  <Name>RealmLoginKitTest</Name>
  <ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>

现在,当您使用 xbuild|MSBuild 构建基于 NUnit 的项目时,它还会构建引用的项目并将其构建工件包含在 NUnit 项目的输出目录中(假设您尚未转关闭本地副本(false),这将在该项目的 Reference 部分中放置一个 <Private>False</Private> 元素。