2017-08-10 4 views
2

ソースから埋め込みリソースを抽出します。私はコンパイラを使用このためコンパイル済みソースからリソースを抽出する

:今

CompilerParameters CP = new CompilerParameters(); 
[...code...] 

CP.EmbeddedResources.Add(@"C:\WindowsFormsApp3.exe"); 

My ressource + the source.txt

を、私は私のファイルにressourceありますwith the ressource

をしかし、私はそれをextract-できますか?私はこのトピックを使用します。How to Read an embedded resource as array of bytes without writing it to disk? をしかし、それはdoesntの仕事だ、何も私のフォルダに表示されません:/

だから、あなたは私を助けることができる場合、私は、フォルダ内のressourceを抽出します。

ありがとう。

+0

私はそれをテストするつもりです。 –

+0

ねえ、私にスクリーンショットを教えてもらえますか、私は名前空間に問題があります:/ありがとう:) –

答えて

0

既定でResources.resx(プロパティの下)を使用して既存のファイルをプロジェクトに追加すると、ビルドアクションはnoneになります。リソースフォルダーの下にあるファイルを選択し、ビルドアクションをEmbeded Resourceに変更する必要があります。つまり、アセンブリーに組み込まれることを意味します。つまり、アセンブリーに含まれません。つまり、Contentです。

がすべて埋め込まリソースのリストを取得するには、あなたがこれを使用することができます:

string[] embededResources = Assembly.GetExecutingAssembly().GetManifestResourceNames(); 

がリソースを使用するには:

//OctoBox: Picturebox 
//Octocat: Octocat.png image 

//Tested with: 
//Build action: Embeded Resource 
// 1st: 
OctoBox.Image = (Bitmap)Resources.ResourceManager.GetObject("Octocat"); 

//2nd 
Assembly asm = Assembly.GetExecutingAssembly(); 
Stream octoStream = asm.GetManifestResourceStream($"{asm.GetName().Name}.Resources.Octocat.png"); 

if (octoStream != null) 
{ 
    OctoBox.Image = Image.FromStream(octoStream); 
    octoStream.Close(); 
} 

//Tested with: 
//Build action: None, Content and embeded resource 
OctoBox.Image = Resources.Octocat; 

インテリセンスで最も簡単である最後の1。

関連する問題