您可以將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)