C # grandchild project dlls not included in msbuild

I have a C # project that references a C # Y project that references a C # project. Thus, the chain of dependencies looks like this: X => Y => Z. There is no direct / explicit dependence X => Z. When I create a package for publishing using the msbuild command

msbuild DesignService.csproj /m /p:Configuration="Debug" /p:Platform="AnyCPU" /verbosity:quiet /t:Package /p:PackageLocation=X.zip /p:PackageAsSingleFile=True 

I get a zip file with DLL files for X and Y, but not Z. Then, when the package is published (in the Azure App Service), I get runtime errors when calling the code in Z, saying that the DLL could not be found. If I add Z as a direct / explicit link in X, it works fine. But I donโ€™t think I should have done it.

How can I get a DLL for Z in my publish package from msbuild without adding an explicit link in X?

+5
source share
1 answer

Why is this happening

X.csproj was called, and since it has a link to the Y.csproj project, it calls Y.csproj - it "goes back." Z.csproj has not yet built, so build breaks.

How to fix

Follow this principle : Do not use the dependencies expressed in the solution file at all.

Instead, you can specify a link to the project in the project. It will look like this: pay attention to the metadata element, and all this is inside the <ItemGroup> , of course:

 <ProjectReference Include="โ€ฆ foo.csproj"> <ReferenceOutputAssembly>false</ReferenceOutputAssembly> </ProjectReference> 

Although it is tedious to edit your projects so that the error disappears, it is best to use the links to the projects and view the solution file simply as a "view".

In the end, you get projects that, if you want, can be created without a solution file.

For more information on how to fix the problem, you can refer to this blog .

+1
source

Source: https://habr.com/ru/post/1276140/


All Articles