VS 2019,SDK 样式库项目。
不知道为什么这是必要的。似乎它应该是一个默认功能。但这对我有用。
<ItemGroup>
<None Include="$(OutputPath)\$(AssemblyName).dll.config" Pack="True" PackagePath="lib\$(TargetFramework)" />
</ItemGroup>
22 年 4 月 11 日更新
这是针对 SDK 样式的 .NET Framework 库。项目文件的相关部分如下:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>...</RootNamespace>
<TargetFramework>net452</TargetFramework>
<Platforms>AnyCPU</Platforms>
<NoWarn>1701;1702;1591</NoWarn>
<AssemblyTitle>...</AssemblyTitle>
<Description>...</Description>
<Company>...</Company>
<Copyright>...</Copyright>
<Version>...</Version>
</PropertyGroup>
<Import Project="$(MSBuildProjectDirectory)\Package.targets" />
...
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitLab" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project>
您可以在下面看到项目文件包含package.targets 的位置。这是所有 NuGet 打包代码所在的位置。
此包包含库的发布和调试版本,并带有 .targets 包含以复制到构建的适当版本中。因此,OutputPath 固定在第 45-59 行。
您要查找的内容位于第 108-114 行:
<!--****************************************************************************
* NuGet Package Configuration
*****************************************************************************-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--=======================================================================-->
<!-- T4 template used to create `build\{tfm}\$(AssemblyName).targets` for -->
<!-- inclusion in the `.nupkg` file. Requires `dotnet-t4` being installed. -->
<!--=======================================================================-->
<BuildTargetsFile>Build.targets.tt</BuildTargetsFile>
<!--===========================================================================-->
<!-- Normally set `true` so deterministic Source Link URLs are generated and -->
<!-- all source requests will go to the remote repository. Setting this to -->
<!-- `false` (debugging only) will look for the source files in the local -->
<!-- directory where this library was built before looking to the remote repo. -->
<!--===========================================================================-->
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
<!--====================================-->
<!-- Temporary folder where other tools -->
<!-- puts files required by this file. -->
<!--====================================-->
<TempFilesPath>$(SolutionDir)\output</TempFilesPath>
</PropertyGroup>
<ItemGroup>
<!--================================================================-->
<!-- Change Source Link host to proxy where GitLab repo URLs are -->
<!-- converted to GitLab API requests with required authentication. -->
<!--================================================================-->
<SourceLinkGitLabHost Include="gitlab.com" ContentUrl="https://gitlabproxy.loc" />
</ItemGroup>
<!--========================================================-->
<!-- `Version.targets` is updated by `npm version` command. -->
<!--========================================================-->
<Import Project="$(MSBuildProjectDirectory)\Version.targets" />
<!--==============================================-->
<!-- Fix the output paths so we can build a NuGet -->
<!-- package with both Release and Debug builds. -->
<!--==============================================-->
<PropertyGroup>
<DebugOutputPath>bin\Debug</DebugOutputPath>
</PropertyGroup>
<Choose>
<When Condition="'$(Configuration)' == 'Debug'">
<PropertyGroup>
<OutputPath>$(DebugOutputPath)</OutputPath>
</PropertyGroup>
</When>
<When Condition="'$(Configuration)' == 'Release'">
<PropertyGroup>
<OutputPath>bin\Release</OutputPath>
</PropertyGroup>
</When>
</Choose>
<!--==================================================================-->
<!-- Nuget Package can only be created in Release mode, using `dotnet -->
<!-- pack`, after the Debug build, and must include the Debug output. -->
<!-- -->
<!-- Title tag missing from UI. -->
<!-- https://github.com/dotnet/project-system/issues/2937 -->
<!--==================================================================-->
<PropertyGroup>
<Title>$(AssemblyTitle)</Title>
<Authors>$(Company)</Authors>
<!--===========================================================-->
<!-- Include `.pdb` file in `.nupkg` so it will be downloaded -->
<!-- with the `.dll`. GitLab does not provide a symbol server. -->
<!-- https://gitlab.com/gitlab-org/gitlab/-/issues/342157 -->
<!--===========================================================-->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<!--<IncludeSymbols>true</IncludeSymbols>-->
<!--<SymbolPackageFormat>snupkg</SymbolPackageFormat>-->
</PropertyGroup>
<!--===========================================================-->
<!-- Build Intellisense file in Release mode. This is required -->
<!-- for `pack` to include the file in the NuGet package. -->
<!--===========================================================-->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<!--==============================================================================-->
<!-- Add files to include in `.nupkg` file before packing. -->
<!-- -->
<!-- These are temporary files so we don't want them referenced in the project -->
<!-- but only included files can be packed (`Pack="True"` is ignored for `<None -->
<!-- Remove="..."/>`). To keep the references out of the project, these files -->
<!-- are only included here. -->
<!-- -->
<!-- https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target -->
<!--==============================================================================-->
<Target Name="BeforePack" BeforeTargets="_GetPackageFiles">
<!--===============================================================-->
<!-- Pack is only allowed in Release build. Debug build must have -->
<!-- already been done so debug assembly can be added to `.nupkg`. -->
<!--===============================================================-->
<Error Condition="'$(Configuration)' != 'Release'" Text="`pack` target is only available in 'Release' mode." />
<!--==================================================-->
<!-- This copies the library config file to the -->
<!-- package. Seems like this shouldn't be necessary. -->
<!--==================================================-->
<ItemGroup Condition="Exists('$(OutputPath)\$(AssemblyName).dll.config')">
<None Include="$(OutputPath)\$(AssemblyName).dll.config" Pack="True" PackagePath="lib\$(TargetFramework)" />
</ItemGroup>
<!--=================================================-->
<!-- Pack debug assembly files into `libdbg` folder. -->
<!--=================================================-->
<ItemGroup>
<None Include="$(DebugOutputPath)\$(TargetFramework)\$(AssemblyName).dll" Pack="True" PackagePath="libdbg\$(TargetFramework)" />
<None Include="$(DebugOutputPath)\$(TargetFramework)\$(AssemblyName).pdb" Pack="True" PackagePath="libdbg\$(TargetFramework)" />
</ItemGroup>
<!--==========================================-->
<!-- Copy Intellisense file created from -->
<!-- Doxygen output over the file VS created. -->
<!--==========================================-->
<copy Condition="Exists('$(TempFilesPath)\$(AssemblyName).xml')" SourceFiles="$(TempFilesPath)\$(AssemblyName).xml" DestinationFolder="$(OutputPath)" />
<!--==================================================-->
<!-- Create the `build\{tfm}\$(AssemblyName).targets` -->
<!-- file from T4 template and add to package. -->
<!-- -->
<!-- https://github.com/nogic1008/T4Sample -->
<!--==================================================-->
<PropertyGroup>
<BuildTargetsPath>$(IntermediateOutputPath)\$(AssemblyName).targets</BuildTargetsPath>
</PropertyGroup>
<Exec WorkingDirectory="$(ProjectDir)"
Command="dotnet t4 "$(BuildTargetsFile)" -o "$(BuildTargetsPath)" -pAssemblyName="$(AssemblyName)"" />
<ItemGroup>
<None Include="$(BuildTargetsPath)" Pack="True" PackagePath="build\$(TargetFramework)\" />
</ItemGroup>
</Target>
<!--=============================================-->
<!-- Source Link -->
<!-- https://github.com/dotnet/sourcelink#gitlab -->
<!--=============================================-->
<ItemGroup>
<!--======================================================================================================-->
<!-- Assembly Info generated into `AssemblyInfo.cs` and embedded in `.dll`. -->
<!-- https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#assembly-attribute-properties -->
<!--======================================================================================================-->
<EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)" />
</ItemGroup>
<PropertyGroup>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<!--=================================================-->
<!-- Embed generated `AssemblyInfo.cs`. -->
<!-- https://github.com/dotnet/sourcelink/issues/572 -->
<!--=================================================-->
<!--<EmbedUntrackedSources>true</EmbedUntrackedSources>-->
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>
</Project>
希望对你有帮助。