工作上還有些用 wdproj 的專案,由於 Visual Studio 從 2012 起已不再支援 wdproj,雖然可以透過 MSBuild 編譯,但它在 Solution 會呈現無法載入狀態,不時提醒著「別人都已上太空,我還在殺豬公」,有股淡淡違和感。

VS2012+ 雖然不支援 .wdproj,但針對 Web Site project 也有提供編譯成 dll 部署的解決方案,在專案按右鍵選 Publish Web App 叫出設定建立 Profile:

Profile 可指定預先編譯,決定要全部編成一個 dll 或是一個資料夾一個 dll,實質上可完全取代 .wdproj。

上述設定會產生兩個相關檔案,FolderProfile.pubxml 儲存部署目的地等 Profile 設定,website.publishproj 則是編譯相關設定:

如果要做批次編譯或自動編譯,指令範例如:msbuild WebSite\website.publishproj /p:DeployOnBuild=true;PublishProfile=X:\Temp\WebSite\App_Data\PublishProfiles\FolderPRofile.pubxml (PublishProfile 要給完整路徑)

就醬,終於可以跟 wdproj 徹底說 Bye-Bye 囉~

Tips of how to use publish profile for web site project to replace .wdproj.


Comments

# by

抱歉挖出這麼舊的文章,但實在不知道該怎麼解決這問題 在 visual studio 建立一個 .net core worker 專案,使用 visual studio 的發佈功能,選擇發佈到資料夾,之後不管怎麼修改 pubxml,都不會產生預期的效果,像是不把檔案複製到發佈資料夾,或是發佈後顯示訊息之類的 但在 .net core web 專案時明明就很正常,不知道這算不算臭蟲,還是 worker 專案必須特別設定才能讓 visual studio 的發佈設定檔有作用 目前的替代方法是在命令列下 dotnet publish 指定發佈設定檔,但除了這方法,完全想不到要怎麼去解決 visual studio 發佈按鈕不去讀取 pubxml 中 PropertyGroup 以外內容的問題,不知道黑大對這問題有沒有頭緒? 附上 pubxml 內容 <?xml version="1.0" encoding="utf-8"?> <!-- https://go.microsoft.com/fwlink/?LinkID=208121. --> <Project> <PropertyGroup> <Configuration>Release</Configuration> <Platform>Any CPU</Platform> <PublishDir>bin\Release\net8.0\publish\linux-x64\</PublishDir> <PublishProtocol>FileSystem</PublishProtocol> <_TargetId>Folder</_TargetId> <TargetFramework>net8.0</TargetFramework> <SelfContained>false</SelfContained> <RuntimeIdentifier>linux-x64</RuntimeIdentifier> <PublishSingleFile>true</PublishSingleFile> <PublishProfile>Properties\PublishProfiles\FolderProfile.pubxml</PublishProfile> </PropertyGroup> <ItemGroup> <MsDeploySkipRules Include="CustomSkipFile"> <ObjectName>filePath</ObjectName> <AbsolutePath>appsettings.Development.json</AbsolutePath> </MsDeploySkipRules> </ItemGroup> <ItemGroup> <None Include="appsettings.Development.json" CopyToOutputDirectory="Never" CopyToPublishDirectory="Never" /> </ItemGroup> <ItemGroup> <None Update="appsettings.Development.json"> <CopyToOutputDirectory>Never</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> <Target Name="Test" AfterTargets="Build"> <Message Text="Test" /> </Target> </Project>

# by Jeffrey

to 貴,看文件 https://learn.microsoft.com/zh-tw/dotnet/core/extensions/windows-service#publish-the-app BackgroundService 也能用 .pubxml 發行,要丟個可重現問題的專案到 github 讓大家幫測嗎?

# by

https://github.com/j108251113/TestWorkerServicePubLish 麻煩黑大了

# by

剛剛測試又成功了,之前不知道哪個地方做錯了導致沒在發佈後成功移除 appsettings.Deveopment.json

# by

看來問題出在 Worker Service 必須明確指定 PublishProfile 才能讓 Visual Studio 發佈時主動去讀取 .pubxml,沒指定可能就只會自動複製 PropertyGroup 的內容當成預設的 .pubxml 因為我在這個測試專案成功後,回到開發專案上沒在 .pubxml 中指定 PublishProfile 依舊沒有出現我想要的效果,加上去就成功了

Post a comment