Reputation: 502
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?
Upvotes: 10
Views: 5425
Reputation: 206
The problem is caused by Microsoft.NET.Sdk.props: <AssemblySearchPaths>
does not have any <ReferencePath>
.
I have fixed it by adding this to the .csproj:
<PropertyGroup>
<AssemblySearchPaths>
$(AssemblySearchPaths);
$(ReferencePath);
</AssemblySearchPaths>
</PropertyGroup>
Upvotes: 10
Reputation: 5801
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
Upvotes: 1
Reputation: 19330
referencePath
is ignored with new project file format. /t:restore
to msbuild command along with build target, so it will restore and build at same time. <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.
Upvotes: 3