来自`.csproj`的Nuget包不会替换样本值

时间:2016-06-14 13:43:33

标签: cmd nuget nuget-spec

我试图自动构建nuget包,但是我有一些示例值的问题,比如许可URL,图标URL等。我希望能够替换项目URL,标签和摘要,同时完全删除了许可证URL和图标URL ...我从CMD自动执行此操作,并且我无法找到这些值的任何属性,我可以将其粘贴在程序集信息中。 ..我该怎么做?

2 个答案:

答案 0 :(得分:1)

答案是使用AssemblyMetadataAttribute。

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

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

答案 1 :(得分:0)

我发现无法以这种方式设置它,因此我只需使用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