简体   繁体   中英

How to exclude a dependency from nuget package in Visual studio

I have a solution that consume a nuget that have all DTO classes(DataObjects).

When developing I want to create new DTO's. To avoid to have to add the DTO to the external project DataObjects and recompile and republish the nuget just to have access to the new DTO in my project, I have created a project(DevObjects) that have the same namespace. I just pop a new DTO class into DevObjects and continue developing. When I'm done with that particular job I move the DTO to the DataObjects recompile and publish the nuget.

This works fine except that when I publish the the library that I was working on as a nuget, it list DevObjects as a dependency even thou it is not referenced in code.

How can I exclude DevObjects from the library nuget?

The only workaround I can think of is to publish a dummy nuget of DevObjects just to make nuget happy, but it does not feel like a palatable solution.

When I'm done with that particular job I move the DTO to the DataObjects recompile and publish the nuget.

I think you have added project reference like DevObjects which contains the file DTO into DataObjects project Also, l think the projects are based on Net Standard. When you package DataObjects , it will generate the dependency to DevObjects . This is the normal behavior.

In a way, when you package the project as nuget, the generation of dependencies really means adding project references.

How can I exclude DevObjects from the library nuget?

You can just remove DevObjects by some changes into DataObjects.csproj

> change the include into remove

 <ProjectReference Remove="..\xxxx\DevObjects.csproj" />

Besides , you can exclude the reference project by UI Control.( Right-click on DataObjects-->Dependencies-->Add Reference-->Projects-->uncheck DevObjects )

Conclusion

When you package a project, the Project Reference adds a dependency to your nuget package. So if you do not want to have this dependency, you can just add the DTO class as an Existing Item into DataObjects project. Hope it could help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM