msbuild - 将 .dll 引用添加到构建之前生成的 nuget
问题描述
我正在使用 nuget 部署一个 MsBuild 任务,它会在每次构建之前生成一个 .dll。
我无法在References
消费者的 Visual Studio 项目中获取节点中引用的生成的 dll。
我也在使用 MSBuild 来构建.nupkg
文件。build/
生成和编译工作正常,我在目录中部署以下目标
<Project>
<!-- this will automatically run before the 'Build' target -->
<Target Name="GenerateAndBuild" BeforeTargets="Build">
<!--the deployed task that generates the code-->
<Utils.CreateUtilResourceTask/>
<ItemGroup>
<CompileGeneratedSources Include="GeneratedClass.cs" />
</ItemGroup>
<MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
<Csc Sources="@(CompileGeneratedSources )" OutputAssembly="$(OutputPath)Util.dll" TargetType="library" EmitDebugInformation="true" />
<Delete Files="@(CompileGeneratedSources )" />
</Target>
</Project>
这会util.dll
在项目输出文件夹中生成,但我无法在使用项目中引用它。我认为这将在.csproj
文件中起作用:
<PropertyGroup>
<TargetFrameworks>netstandard1.6;net46</TargetFrameworks>
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<VersionPrefix>0.1.1</VersionPrefix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageOutputPath>$(MSBuildThisFileDirectory)</PackageOutputPath>
<PackageId>BuildUtil</PackageId>
<!-- that does not add a refenrece in consuming projects -->
<references>
<reference file="$(OutputPath)Util.dll"/>
</references>
<files>
<file src="$(OutputPath)Util.dll"/>
</files>
</PropertyGroup>
也许有人对此有暗示?
解决方案
您需要在ItemGroup而不是 PropertyGroup 中声明程序集引用。例如:
<ItemGroup>
<Reference Include="$(OutputPath)Util.dll" />
</ItemGroup>
推荐阅读
- c# - 在 DevExpress PivotGridControl 中使用 DisplayNameAttribute
- python - 具有特定重复的元素数组的 Python 排列
- java - 没有插入数据,也没有在 android sqlite 中引发异常
- javascript - Socket IO如何向一个特定的人发送消息
- c# - 无法在 Xamarin 中的 ListView 上获取 Item Tap 事件
- spring-mvc - 2个微服务之间的通信
- python - Python Pandas Dataframe 数据时间列分离功能
- c# - 在 Visual Studio 2012 中以编程方式配置 NLog
- android - 如何使用 Parcel.readTypedList() 以及来自 kotlin-android-extensions 的 @Parcelize?
- javascript - 确定给定点js的所有元素