简体   繁体   English

使用我们自己的 Nuget package 安装时,如何将 PostSharp 包含在 ASP.NET WebApi 项目的构建过程中?

[英]How to have PostSharp included in build process for ASP.NET WebApi project when installed using our own Nuget package?

We have a class library (C#, .NET 5) where we've added a reference to the PostSharp nuget-package (using PackageReference in our csproj-file) and implemented a PostSharp OnMethodBoundaryAspect .我们有一个 class 库(C#、.NET 5),我们在其中添加了对 PostSharp nuget 包的引用(在我们的 csproj 文件中使用PackageReference )并实现了 PostSharp OnMethodBoundaryAspect This class library is then packaged into a Nuget package to be consumed by our micro services/WebApi-projects.然后将这个 class 库打包成一个 Nuget package 供我们的微服务/WebApi 项目使用。

When I add a reference to this nuget-package in one of our ASP.NET WebApi project I see that references to PostSharp and PostSharp.Redist are also being included along with our class library.当我在我们的 ASP.NET WebApi 项目之一中添加对此 nuget 包的引用时,我看到对 PostSharp 和 PostSharp.Redist 的引用也包含在我们的 class 库中。

However, when adding the OnMethodBoundaryAspect to one of our functions in the WebApi-project the code in the aspect is not being executed.但是,当将OnMethodBoundaryAspect添加到 WebApi 项目中的一个函数时,方面中的代码未被执行。 If I add a reference to PostSharp directly in the WebApi-project it works just fine.如果我直接在 WebApi 项目中添加对 PostSharp 的引用,它就可以正常工作。

How do I make sure that PostSharp is being included in the build process in our WebApi-project when it is being included from our own Nuget-package?当 PostSharp 被包含在我们自己的 Nuget 包中时,我如何确保它被包含在我们的 WebApi 项目的构建过程中?

This answer to another question ( https://stackoverflow.com/a/68470518/182380 ) on StackOverflow mentions that PostSharp.targets needs to be included in the build process and installing the PostSharp nuget-package will make this happen, but what if I want to include PostSharp from our own Nuget-package and have it included in the build process of the WebApi-project that way, how do I go about fixing that? StackOverflow 上对另一个问题 ( https://stackoverflow.com/a/68470518/182380 ) 的回答提到PostSharp.targets需要包含在构建过程中并且安装 PostSharp nuget-package 将实现这一点,但是如果我想从我们自己的 Nuget 包中包含 PostSharp,并以这种方式将其包含在 WebApi 项目的构建过程中,我 go 如何解决这个问题?

This is a result of NuGet's behavior of project references (build-time parts of the package are not taken from referenced projects).这是 NuGet 的项目引用行为的结果(package 的构建时部分未从引用的项目中获取)。

For your own package, it should be enough to have a dependency (in the.nuspec file or appropriately configured csproj) on PostSharp package, which would then include all PostSharp package assets in the project where you've referenced your package (this is the default behavior of NuGet dependency if you don't specify any includeAssets and excludeAssets ).对于您自己的 package,在PostSharp package 上具有依赖性(在 .nuspec 文件或适当配置的 csproj 中)就足够了,这将在您引用 package 的项目中包含所有PostSharp package 资产(这是NuGet 依赖项的默认行为(如果您未指定任何includeAssetsexcludeAssets )。

In case of PackageReference in your project file, you also need to set privateAssets to none , because the default behavior is Build,Analyzers :如果您的项目文件中有PackageReference ,您还需要将privateAssets设置为none ,因为默认行为是Build,Analyzers

<PackageReference Include="PostSharp" Version="6.9.9" PrivateAssets="none" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 升级ASP.Net WebAPI nuget包后出错 - Error after upgrading ASP.Net WebAPI nuget package 使用NuGet,PostSharp和Jenkins编译.NET项目 - Compiling a .NET project using NuGet, PostSharp and Jenkins 如何使用Asp.Net C#获取客户端IP地址-当我们的项目托管在IIS中时 - How to Get Client IP Address using Asp.Net C# - When our Project is Hosted in IIS 如果已经安装了SDK,为什么需要使用nuget将ASP.NET Core软件包添加到项目中? - Why do I need to use nuget to add ASP.NET Core packages into my project if I already have the SDK installed? 如何将某些视图和文件夹排除在已部署的ASP.NET MVC NuGet包中? - How can I exclude some views and folders from being included into the deployed ASP.NET MVC NuGet package? 如何为 nuget 包构建具有多个 .net 框架的项目 - How can I build a project with multiple .net frameworks for nuget package 如何使用Asp.net 5(dnu pack)指定Nuget包ID - How to specify Nuget Package Id with Asp.net 5 (dnu pack) OnExit 不是通过 PostSharp 进入 asp.net 项目 - OnExit is not entering via PostSharp in asp.net project 在现有的ASP.NET MVC 5项目中使用WebAPI 2.2 - Using WebAPI 2.2 inside of an existing ASP.NET MVC 5 project Visual Studio,ASP.Net(.Net Framework),并在项目中包含NuGet安装的软件包 - Visual Studio, ASP.Net (.Net Framework) and including NuGet installed packages in a project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM