Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# grandchild project DLLs not included in msbuild package

I have a C# project X that references a C# project Y that references a C# project Z. So the dependency chain looks like this: X => Y => Z. There is no direct/explicit dependency X => Z. When I build a package for publication using 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 that has DLLs for X and Y, but not Z. Then when the package is published (to an Azure App Service) I get runtime errors when a call is made to code in Z, saying the DLL can not be found. If I add Z as a direct/explicit reference in X, it works just fine. But I don't think I should have to do this.

How can I get DLLs for Z in my publish package from msbuild without adding an explicit reference in X?

like image 397
Scotty H Avatar asked Mar 28 '18 19:03

Scotty H


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


1 Answers

Why does this happen

X.csproj was invoked, and because it has a project reference to Y.csproj, it invokes Y.csproj — it “goes around the back”. Z.csproj hasn’t necessarily built yet, so the build breaks.

How to fix

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

You could put a project reference in the project instead. It would look like this – note the metadata element, and all this is inside an <ItemGroup> tag of course:

<ProjectReference Include=”… foo.csproj”> 
    <ReferenceOutputAssembly>false</ReferenceOutputAssembly> 
</ProjectReference>

Although it’s tiresome to have to edit your projects in this way to make the bug go away, it’s a best practice to use project references instead and consider the solution file merely a “view”.

You’ll end up with projects that if you want can be built without a solution file.

For more details about how to fix the problem, you could refer to this blog.

like image 128
Joey Cai Avatar answered Sep 25 '22 12:09

Joey Cai