【问题标题】:.NET Core - build project specifying ReferencePath.NET Core - 构建项目指定 ReferencePath
【发布时间】:2018-10-08 00:37:51
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# .net msbuild .net-core csproj


    【解决方案1】:
    1. 您仍然可以使用 MSBUILD 在解决方案中构建 .net CORE/Standard 项目。
    2. 这似乎是我向 Microsoft 报告的一个错误(这与核心/标准无关,而是新项目文件格式)referencePath 被新项目文件格式忽略。
    3. /t:restore 与构建目标一起添加到 msbuild 命令中,这样它将同时恢复和构建。
    4. 针对您的 CI/Build 服务器情况的解决方法是创建一个特殊的解决方案配置,并将类似于以下内容添加到您的项目文件中
    <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 中更改配置名称并完成这项工作。

    【讨论】:

      【解决方案2】:

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

      <PropertyGroup>
          <AssemblySearchPaths>
              $(AssemblySearchPaths);
              $(ReferencePath);
          </AssemblySearchPaths>
      </PropertyGroup>
      

      【讨论】:

      • 您还有其他选择吗?我试过这个,但它没有帮助。
      【解决方案3】:

      但是“dotnet build”没有类似的说法。

      你为什么这么说?

      dotnet cli 仍然支持使用-p 而不是/p 的“属性注入”。 Link (Search for "-p")

      对于您的问题,build 命令将如下所示:

      dotnet build -p:ReferencePath=xxx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-07
        • 2018-07-09
        • 2017-12-19
        • 2018-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多