在某些狀況,可能會想把 wwwroot 包起來,以防止遇到不預期的修改,雖然以下方式也只是簡易的防君子不防小人的方式。 首先以 ASP.NET Core 使用者入門的範例為例,建立一個新專案並直接發行它:
1
dotnet new razor -o aspnetcoreapp
將此專案發行到 out 資料夾中:
1
dotnet publish -c release -o out
完成後進到 out 資料夾中,可以看到以下檔案:
1 2 3 4 5 6 7 8 9 10 11 12 13
$ ls -l total 408 -rw-r--r-- 1 North 1049089178 Mar 2814:14 appsettings.Development.json -rw-r--r-- 1 North 1049089113 Mar 2814:14 appsettings.json -rwxr-xr-x 1 North 104908968096 Mar 2814:37 aspnetcoreapp.PrecompiledViews.dll* -rw-r--r-- 1 North 104908942496 Mar 2814:37 aspnetcoreapp.PrecompiledViews.pdb -rw-r--r-- 1 North 1049089280120 Mar 2814:37 aspnetcoreapp.deps.json -rwxr-xr-x 1 North 10490897168 Mar 2814:36 aspnetcoreapp.dll* -rw-r--r-- 1 North 10490891668 Mar 2814:36 aspnetcoreapp.pdb -rw-r--r-- 1 North 1049089221 Mar 2814:37 aspnetcoreapp.runtimeconfig.json -rw-r--r-- 1 North 1049089628 Mar 2814:14 bundleconfig.json -rw-r--r-- 1 North 1049089387 Mar 2814:37 web.config drwxr-xr-x 1 North 10490890 Mar 2814:37 wwwroot/
把 out 資料夾清空後再重新發行後,可以看到 wwwroot 資料夾不見了,且aspnetcoreapp.dll 的檔案大小大了不少:
1 2 3 4 5 6 7 8 9 10 11 12
$ ls -l total 2420 -rw-r--r-- 1 North 1049089178 Mar 2814:14 appsettings.Development.json -rw-r--r-- 1 North 1049089113 Mar 2814:14 appsettings.json -rwxr-xr-x 1 North 104908968096 Mar 2814:59 aspnetcoreapp.PrecompiledViews.dll* -rw-r--r-- 1 North 104908942496 Mar 2814:59 aspnetcoreapp.PrecompiledViews.pdb -rw-r--r-- 1 North 1049089280120 Mar 2814:59 aspnetcoreapp.deps.json -rwxr-xr-x 1 North 10490892068480 Mar 2814:59 aspnetcoreapp.dll* -rw-r--r-- 1 North 10490891672 Mar 2814:59 aspnetcoreapp.pdb -rw-r--r-- 1 North 1049089221 Mar 2814:59 aspnetcoreapp.runtimeconfig.json -rw-r--r-- 1 North 1049089628 Mar 2814:14 bundleconfig.json -rw-r--r-- 1 North 1049089387 Mar 2814:59 web.config