.NET Core - build project specifying ReferencePath

天大地大妈咪最大 提交于 2019-12-10 16:46:10

问题


I have a .csproj for the .NetCore platform with classic references. I'm using the hintpath attribute for the development environment. But I should build csproj on the CI-environment where referenced assemblies are placed in the different directory. On the classic net4 I've used the /p:ReferencePath argument for the MSBuild tool. But the "dotnet build" has no similar argument. As a fallback I found the "dotnet msbuild" command but this tool is ignores the /p:ReferencePath=xxx argument and shows me

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.

Please guide me, what can I check, where dotnet-build/dotnet-msbuild tools are searching the referenced assemblies and how to specify that directory?


回答1:


  1. You can still build .net CORE/Standard projects in solution using MSBUILD.
  2. It is seem to be a bug which I reported to Microsoft that (and this is not about core/standard but rather new project file format) referencePath is ignored with new project file format.
  3. Supply add /t:restore to msbuild command along with build target, so it will restore and build at same time.
  4. The work-around for your CI/Build server situation is to create a special solution configuration, and add similar to following into your project file
<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>  

This will allow you to just change configuration name in CI/Build and will do the job.




回答2:


Problem is coused by Microsoft.NET.Sdk.props: AssemblySearchPaths has no ReferencePath. Fixed by adding to csproj:

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



回答3:


But the "dotnet build" has no similar argument.

Why are you saying that?

The dotnet cli still support "property injection" with -p instead of /p. Link (Search for "-p")

For your question, the build command will look like this command:

dotnet build -p:ReferencePath=xxx



来源:https://stackoverflow.com/questions/50057777/net-core-build-project-specifying-referencepath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!