LoginSignup
1
0

More than 3 years have passed since last update.

C# csc.rspファイルを編集してcsc.exeのデフォルトのオプションを変更しようと思ったらファイルアクセス権が面倒だった話(Visual Studio使わない人向け)

Last updated at Posted at 2019-11-01

(結論)

csc.rspは編集せずに、バッチファイルつくるのがおすすめ()

はじめに

Windows10環境です。

csc.exeのあるフォルダ1csc.rspというファイルがあり、
これを編集するとオプションを変えられます。
が、そのままだと上書き保存ができません

csc.rspの中身

デフォルトは下記になっているはず。

csc.rsp

# This file contains command-line options that the C#
# command line compiler (CSC) will process as part
# of every compilation, unless the "/noconfig" option
# is specified. 

# Reference the common Framework libraries
/r:Accessibility.dll
/r:Microsoft.CSharp.dll
/r:System.Configuration.dll
/r:System.Configuration.Install.dll
/r:System.Core.dll
/r:System.Data.dll
/r:System.Data.DataSetExtensions.dll
/r:System.Data.Linq.dll
/r:System.Data.OracleClient.dll
/r:System.Deployment.dll
/r:System.Design.dll
/r:System.DirectoryServices.dll
/r:System.dll
/r:System.Drawing.Design.dll
/r:System.Drawing.dll
/r:System.EnterpriseServices.dll
/r:System.Management.dll
/r:System.Messaging.dll
/r:System.Runtime.Remoting.dll
/r:System.Runtime.Serialization.dll
/r:System.Runtime.Serialization.Formatters.Soap.dll
/r:System.Security.dll
/r:System.ServiceModel.dll
/r:System.ServiceModel.Web.dll
/r:System.ServiceProcess.dll
/r:System.Transactions.dll
/r:System.Web.dll
/r:System.Web.Extensions.Design.dll
/r:System.Web.Extensions.dll
/r:System.Web.Mobile.dll
/r:System.Web.RegularExpressions.dll
/r:System.Web.Services.dll
/r:System.Windows.Forms.Dll
/r:System.Workflow.Activities.dll
/r:System.Workflow.ComponentModel.dll
/r:System.Workflow.Runtime.dll
/r:System.Xml.dll
/r:System.Xml.Linq.dll

csc.rspのアクセス権の変更~編集~保存

'1. 下記でファイルの所有権を変更。


cd \Windows\Microsoft.NET\Framework64\v4.0.30319\
takeown /f csc.rsp

'2. エクスプローラでファイルcsc.rspを右クリックし、プロパティを開く。

'3. 「セキュリティ」タブを開く。

'4. 「編集」を押す。(下図参照)
image.png

'5. Administatorsの「許可」に「変更」権限を追加する(「変更」をチェックすると「書き込み」もチェックされる)。(下図参照)
image.png
(※AdministratorsではなくUsersにしておけば以降管理者権限不要のはずだが、不安なのでAdministratorsにしておく。)

'6. メモ帳(notepad.exe)を右クリックで管理者として実行。(メモ帳じゃなくても可)

'7. デバイスへの変更許可が求められるので、承諾する。

'8. csc.rspをstep 6のエディタで編集して上書き保存する。

めんどくさっ

追加したくなりそうなオプション

/nologo ・・・ cscのバージョン表示とかを抑制
/target:winexe ・・・ 生成したexe実行時にコンソールを表示しない(※デバッグ作業中は不便なので微妙)
/platform:x64 もしくは /platform:x86 ・・・ 64bit/32bit指定
/r:DLLのパス ・・・ バッチファイルにしたほうが良い気がする。

csc.rspを編集するデメリット

  • 環境変わったときに戸惑う。 (PC変えたり、ほかの人との環境が変わってしまう。リリース時に事故るリスクがある。)
  • 戻すとき面倒。
  • 変更元をバックアップしてないと戻せなくなるかも。

記事を書いてみたものの、個別にバッチファイル(.bat)作ったほうがよいのではないか・・。

バッチファイル例

compile.bat

csc /r:ほげほげ.dll ^
   /nologo ^
   /target:winexe ^
   %*
  • 行末の ^ は 改行を無視してつなげるためです。(C言語の行末のエスケープ\みたいなもの。)
  • %*は、コマンドラインオプションがそのまま渡ります。(compile.bat /xxx yyy.csとすると、/xxx yyy.csの部分が入ります。)

参考サイト

csc.rsp
https://www.atmarkit.co.jp/fdotnet/dotnettips/179cscrsp/cscrsp.html

ファイル所有者の変更(takeown /f ファイル名)
https://freesoft.tvbok.com/windows7/general/trustedinstaller.html


  1. where csc で調べられます。この辺(C:\Windows\Microsoft.NET\Framework64\v4.0.30319\)にいるはず(環境による)。 

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0