投稿

ラベル(.Net Framework)が付いた投稿を表示しています

[Azure]AppServiceへのデプロイをストレージBlob経由でできるか?

Webアプリは.NetFrameworkなのでビルドは以下の通り。 $msbuild = Resolve-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\*\*\MSBuild\*\bin\msbuild.exe" $msbuild = $msbuild[0] $msbuild {projectFilePath} /t:Build /p:DeployOnBuild=true /p:Configuration=Release /p:RestorePackages=true /p:PublishUrl="./Publish" /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True .Netの場合は dotnet build --configuration release dotnet publish --configuration release --output ./Publish モジュールができたらあとは、ストレージにアップして、どうにかAppServiceへデプロイする。  参考 Run From Package: a new way to deploy your Azure Web Apps and Function Apps #84 Blobにzipファイルをアップする。 共有リンクを取得する。 AppServiceのAppSettingにWEBSITE_RUN_FROM_PACKAGE=<BlobURL>を追加する。 AppSeriviceを再起動する。 ZIP パッケージから Azure App Service のアプリを直接実行する   Deploying App Services with ‘Run From Package’, Azure Storage, and Azure Pipelines

c# .netframework WebAPIで呼び出し元をNLogする

APIで呼び出し元を出力する必要があったのでメモしておく。 System.Collectionsは、nugetでインストールする必要があるかもしれない。 dynamicはstringでキャストしないとExceptionを吐く。 using System.Collections.Generic; [RoutePrefix("api")] public class ApiTestController : ApiController { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private string httpContext = "MS_HttpContext"; /// /// ログイン /// /// For Debug [HttpGet] [Route(nameof(Index))] public Dictionary<string, string> Index() { logger.Info("=== Index Controller START"); dynamic ctx = this.Request.Properties[httpContext]; if (ctx != null) { logger.Info("UserHostAddress: {0}", (string)ctx.Request.UserHostAddress); logger.Info("UrlReferrer {0}", (string)ctx.Request.UrlReferrer); Dictionary<string, string> dict = new ...

Dotnet FrameworkでSystem.Diagnostics.ConsoleTraceListenerを使う

Console Applicationを作成する。 App.configは以下の通り。 <configuration > <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> </startup> <system.diagnostics> <sources> <source name="TraceTest" switchName="sourceSwitch" switchType="System.Diagnostics.SourceSwitch"> <listeners> <add name="Console"/> <add name="myListener"/> <remove name="Default"/> </listeners> </source> </sources> <switches> <!--<add name="sourceSwitch" value="Warning"/>--> <!--<add name="sourceSwitch" value="Information"/>--> <add name="sourceSwitch" value="Verbose"/> </switches> <sharedListeners> <add name="myListener" type="System.Diagnostics.TextWriterTraceL...

web.configにNlog設定を踏襲し、変換構文を使ってソリューション構成ごとに異なるログ設定をする

アクション 最初に以下を宣言する。 これで、ソースコードにはログを貼るだけでよくなる。   <configSections>     <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>   </configSections> あとは、targetとruleを付けるだけ。 全体像は以下の通り。 Web.config <configuration>   <configSections>     <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>   </configSections>   <nlog>     <targets>       <target name="logFile" type="File" fileName="./logs/${shortdate}-debug.log" encoding="UTF-8"         archiveFileName="${basedir}/logs/archives/archive.${shortdate}-debug.log" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="365"         layout="${longdate},${uppercase:${level}},${callsite},${callsite-linenumber},${message}"/>       <!--       <target name=...

シンプルにMSbuildコマンドを使う(Visual Studio2019 Community)

MSBuildを使ってビルドしたのでメモる。 ■ MSBuildのパスは以下の通り。 ↓をWindowsの環境変数に登録する。 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin ■ Release Build msbuild /p:Configuration=Release /t:Rebuild     ■ Publish Build SET MSBuildPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\ SET BuildPath=F:\work\DotNetFramework\WebMVC   "%MSBuildPath%\MSBuild.exe" "%BuildPath%\WebMVC.csproj" /t:Build /p:DeployOnBuild=true /p:Configuration=Release /p:TargetFramework=v4.7.2 /p:PublishProfile=FolderProfile /p:RestorePackages=false /p:SkipPostSharp=true   Publish Build の出力先 \WebMVC\Properties\PublishProfiles \ FolderProfile.pubxml を確認すると、 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   <PropertyGroup>     <DeleteExistingFiles>False</DeleteExistingFiles>     <ExcludeApp_Data>False</ExcludeApp_Data...

ソリューション構成ごとにconfigファイルを作成する

イメージ
.NetFrameworkのソリューション構成ごとにweb.configを作成し、そのconfigファイルの内容を反映させる。 ちょっと、つまずいたのでメモしておく。 (アクション) 1. 新しいソリューション構成を作成する。 2. web.configを作成する。 3. 変換構文の作成 4. .csprojファイルの編集 1. 新しいソリューション構成の作成 Visual Studioの「ビルド」→「構成マネージャー」→「アクティブソリューション構成」→「新規作成」 で、新しいソリューション構成を作成する。 2. web.configの作成 Web.configを右クリックして「Config変換を追加」をクリックすると、先ほど追加した新しいソリューション構成のWeb.configが追加される。 3. 変換構文の作成 前回のブログ を参考に作成する。 <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">     <connectionStrings>         <add name="ConnectionString"           connectionString="Data Source=192.168.44.10.1\SQLEXPRESS;Initial Catalog=AWS_DB;;Connect Timeout=60;Persist Security Info=False; User ID=hoge;Password=1234"           xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>     </connectionStrings>     <appSettings>      ...

web.config debug/releaseの内容を変換構文を使って切り替える

イメージ
.Net Framework のWeb.Debug .config, Web.Release.config の内容を「変換構文」を使って、構成 (Debug/Release) の切り替えによって変えることができたのでメモしておく。   Release 構成でのビルドでは、 Web.config に記載されている要素のうち、以下の3要素を変換構文を使って変更した。 system.web connectionStrings appSettings   1. system.web   compilation debug=true の削除( Release 時は、デバッグ情報は不要) ●Web.configの記述 <system.web>     <compilation debug="true" targetFramework="4.7.2" />     <httpRuntime targetFramework="4.7.2" /> </system.web> 上記から、「debug="true"」を削除するには、 RemoveAttributes を使う。 ●Web.Release.config <system.web>     <!-- Disable Debug Mode -->     <compilation xdt:Transform="RemoveAttributes(debug)" /> </system.web> 2. connectionStrings   DBの接続情報を変更する。 ( Debug / Release時は普通環境変わるだろう ) ●Web.configの記述 <connectionStrings>     <add name="ConnectionString"         connectionString="Data So...