关于c#:. NET Core-建立指定ReferencePath的项目

.NET Core - build project specifying ReferencePath

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

warning MSB3245: Could not resolve this reference. Could not locate the assembly"AssemblyName". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

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


Microsoft.NET.Sdk.props解决了此问题:AssemblySearchPaths没有ReferencePath。
通过添加到csproj进行修复:

1
2
3
4
5
6
<PropertyGroup>
    <AssemblySearchPaths>
        $(AssemblySearchPaths);
        $(ReferencePath);
    </AssemblySearchPaths>
</PropertyGroup>

  • 您仍然可以使用MSBUILD在解决方案中构建.net CORE / Standard项目。
  • 我向Microsoft报告的这似乎是一个错误(该错误与核心/标准无关,而是新的项目文件格式),referencePath被新的项目文件格式忽略。
  • 将add /t:restore与构建目标一起提供给msbuild命令,这样它将同时还原和构建。
  • 针对CI / Build服务器情况的解决方法是创建一个特殊的解决方案配置,并将类似以下内容的内容添加到您的项目文件中
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <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>

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


    But the"dotnet build" has no similar argument.

    你为什么这么说?

    dotnet cli仍支持-p而不是/p的"属性注入"。链接(搜索" -p")

    对于您的问题,build命令将类似于以下命令:

    dotnet build -p:ReferencePath=xxx