1

我有一个想要使用 ClickOnce 发布的 Winforms 应用程序。此应用程序带有一个初始数据库,必须在每台机器上安装一次。经过一番折腾,我想到了使用自定义先决条件来安装 .sdf 文件。我使用 Bootstrapper Manifest Generator (BMG) 为我要运行的 .cmd 文件创建了一个包,并将 .sdf 文件作为“附加文件”包含在内。

我的期望是这两个文件最终会出现在同一个目录中,并且我可以将 .sdf 文件复制到我想要的位置(它们确实会出现在同一个目录中。)先决条件出现了在 Visual Studio 中就好了。它可以很好地部署到客户端系统,并且安装程序很好地启动了先决条件。

唯一的问题是 .cmd 文件正在执行的当前工作目录是 C:\Documents and Settings\\Desktop!

这两个文件(.cmd 或 .sdf)都不在那里——它们是在别处下载的,例如“C:\Documents and Settings\drogers\Local Settings\Temp\VSD5A.tmp”。所以,虽然我知道 xcopy 到哪里,但我不知道从哪里 xcopy。

我该如何解决这个问题?

这是 .cmd 文件:

REM Modify this file to reflect your manufacturer name [FHCRC] and product name [ClickOnceSharedDataDemo].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\FHCRC" mkdir "%TargetBase%\FHCRC"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" mkdir "%TargetBase%\FHCRC\ClickOnceSharedDataDemo"
CACLS "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" /E /T /C /G "Users":C
xcopy shareddata.sdf "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" PAUSE
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" exit /B -1
:EXIT
PAUSE
exit /B 0

谢谢,大卫

4

3 回答 3

1

好吧,我对这个解决方案并不完全满意,但它确实有效。我现在有两个先决条件。第一个只是运行 CACLS 命令来设置权限的命令文件。它基本上是上述的缩短版本:

REM Modify this file to reflect your manufacturer name [Manufacturer] and product name [ProductName].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\Manufacturer\ProductName\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\Manufacturer" mkdir "%TargetBase%\Manufacturer"
if not exist "%TargetBase%\Manufacturer\ProductName" mkdir "%TargetBase%\Manufacturer\ProductName"
CACLS "%TargetBase%\Manufacturer\ProductName" /E /T /C /G "Users":C
:EXIT
ECHO exit /B 0

第二个先决条件是“所有用户 = true”安装项目,该项目有一个位于默认位置的自定义文件夹:“[CommonAppDataFolder][Manufacturer][ProductName]”。我将 sdf 文件放入此文件夹。

最后,我使用 Bootstrapper Manifest Generator 为两者制作包,使第二个依赖于第一个。我将包复制到适当的 VS2010 目录,将它们作为先决条件包含在内,然后发布。

我现在将每台机器的 .sdf 文件发布到 WinXP 和 Win7。为什么这必须如此困难!?!?

我仍在寻找不太复杂的解决方案,可以同时安装到 Windows 7 和 Windows XP。

于 2011-01-22T00:06:06.053 回答
0

您是否尝试过 MSDeploy?它能够满足您的所有需求。

干杯!

于 2011-01-21T21:33:18.173 回答
0

You could just include the .sdf file with the ClickOnce application, then have your program copy it to somewhere else the first time it runs. I never recommend keeping the data in the CLickOnce cache anyway, it's safer to handle it yourself. See if this article helps at all: http://robindotnet.wordpress.com/2009/08/19/where-do-i-put-my-data-to-keep-it-safe-from-clickonce-updates/

于 2011-01-27T09:00:30.320 回答