问题
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:
- You can still build .net CORE/Standard projects in solution using MSBUILD.
- 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. - Supply add
/t:restore
to msbuild command along with build target, so it will restore and build at same time. - 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