.NET Core - 构建项目指定 ReferencePath

k0s*_*t1x 8 .net c# msbuild csproj .net-core

我有一个带有经典参考的.NetCore平台的.csproj。我正在为开发环境使用该属性。但是我应该在 CI 环境中构建csproj,其中引用的程序集放置在不同的目录中。在经典的net4 上,我使用了MSBuild工具的参数。但是“dotnet build”没有类似的论点。作为后备,我找到了“dotnet msbuild”命令,但此工具忽略了该参数并向我显示hintpath/p:ReferencePath/p:ReferencePath=xxx

警告 MSB3245:无法解析此引用。找不到程序集“AssemblyName”。检查以确保程序集存在于磁盘上。如果您的代码需要此引用,您可能会收到编译错误。

请指导我,我可以检查什么,dotnet-build / dotnet-msbuild工具在哪里搜索引用的程序集以及如何指定该目录?

小智 5

问题是由 Microsoft.NET.Sdk.props 提出的:AssemblySearchPaths 没有 ReferencePath。通过添加到 csproj 修复:

<PropertyGroup>
    <AssemblySearchPaths>
        $(AssemblySearchPaths);
        $(ReferencePath);
    </AssemblySearchPaths>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)


T.S*_*.S. 3

  1. 您仍然可以使用 MSBUILD 在解决方案中构建 .net CORE/Standard 项目。
  2. 这似乎是我向微软报告的一个错误(这与核心/标准无关,而是与新项目文件格式有关)referencePath被新项目文件格式忽略。
  3. 与构建目标一起提供添加/t:restore到 msbuild 命令,因此它将同时恢复和构建。
  4. 针对 CI/构建服务器情况的解决方法是创建一个特殊的解决方案配置,并将类似于以下内容的内容添加到您的项目文件中
<Choose>  
  <When Condition="'$(Configuration)|$(Platform)'=='YourSpecialConfiguration|x64'"><!-- attention here -->
    <ItemGroup>
      <Reference Include="your.dllname">
        <HintPath>yourSpecialPath\your.dllname.dll</HintPath><!-- attention here -->
        <Private>true</Private>
      </Reference>
      <!-- more references here -->
  </When>
  <Otherwise>
    <ItemGroup>
      <Reference Include="your.dllname">
        <HintPath>yourRegularPath\your.dllname.dll</HintPath><!-- attention here -->
        <Private>true</Private>
      </Reference>
      <!-- AND more references here -->
  </Otherwise>
</Choose>  
Run Code Online (Sandbox Code Playgroud)

这将允许您只需更改 CI/Build 中的配置名称即可完成这项工作。