来自 .csproj 的 Nuget 包不会替换示例值

Nuget pack from `.csproj` doesn't replace sample values

我正在尝试自动构建 nuget 包,但示例值存在一些问题,例如许可证 URL、图标 URL 等。我想能够替换项目 URL、标签和摘要,同时完全删除许可证 URL 和图标 URL...我正在从 CMD 自动执行此操作,我可以'找不到我可以粘贴在装配信息中的这些值的任何属性...我该怎么做?

我发现这样设置是不可能的,所以我只好使用nuget spec然后使用批处理更改文件。为了将来参考,请参阅下面的相关批次:

nuget spec Extensions.csproj REM create the file

REM deletes all occurences of the licenseUrl
set count=1
for /f "delims=" %%A in ('find /V /I "<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>" Extensions.nuspec') do (
if !count!==1 echo.>Extensions.nuspec
if !count! GTR 1 echo %%A>>Extensions.nuspec
set /A count=!count!+1)

REM deletes all occurences of the IconUrl
set count=1
for /f "delims=" %%A in ('find /V /I "<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>" Extensions.nuspec') do (
if !count!==1 echo.>Extensions.nuspec
if !count! GTR 1 echo %%A>>Extensions.nuspec
set /A count=!count!+1)

REM replaces values with new values
call :FindReplace "Tag1" "C#" Extensions.nuspec
call :FindReplace "Tag2" "Extensions" Extensions.nuspec
call :FindReplace "http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE" "http://www.gitlab.com/roconnor/Extensions" Extensions.nuspec

exit /b 

:FindReplace <findstr> <replstr> <file>
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
  for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
    echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
    <%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
    if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
  )
)
del %temp%\_.vbs
exit /b

:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with

答案是使用 AssemblyMetadataAttribute。

但是为了让它工作,我们需要团队合并这个 PR 并让 NuGet 来实现它:https://github.com/NuGet/NuGet.Client/pull/622

如有必要,我愿意提供 nuget.exe 的自定义版本和修复程序。这是我自己用的