您可以将xml文件添加到其中一个构建操作设置为内容的项目中,并有一个脚本将xml文件从一个项目(如果更新)复制到另一个项目,并将构建操作设置为内容。您可以使用生成后事件使用批处理文件(copyifnewer.bat)复制xml文件:
@echo off
echo Comparing two files: %1 with %2
if not exist %1 goto File1NotFound
if not exist %2 goto File2NotFound
fc %1 %2
if %ERRORLEVEL%==0 GOTO NoCopy
echo Files are not the same. Copying %1 over %2
copy %1 %2 /y & goto END
:NoCopy
echo Files are the same. Did nothing
goto END
:File1NotFound
echo %1 not found.
goto END
:File2NotFound
copy %1 %2 /y
goto END
:END
echo Done.
和后生成事件中说的WinForms项目将是:
call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)\XML\myfile.xml"
"$(ProjectDir)..\WebApp\XML\myfile.xml"
这样,您只需要在winforms项目中编辑一个xml文件,另一个会自动更新。然后可以使用dacris提供的路径访问XML文件,并结合相关文件夹XML。
或者,如果Web应用程序的同一台计算机上运行的客户端的WinForms应用程序,可使用你的公共数据文件夹:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)