using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace ConsoleApp2 {
class Program {
staticvoid Main(string[] args) {
var path = @"c:\users\user\source\repos\TestDialog\TestDialog\Resources\config.xml";
var xml = new XmlSerializer(typeof(Store));
using(var sw=new StreamWriter(path, false, Encoding.UTF8)) {
xml.Serialize(sw, new Store { Num = 0 });
}
}
}
publicclass Store {
publicint Num { get; set; }
}
}
追加したxmlはプロパティウィンドウでビルドアクションをコンテンツに、Include in VSIXをTrueにしておくこと。これが分からなくてINF分失った
publicclass OptionDialog : DialogPage {
[Category("かてごりー")]
[DisplayName("ひょうじめい")]
[Description("せつめい")]
publicint Num { get; set; }
publicstring Path {
get {
var codebase = typeof(Dialog).Assembly.CodeBase;
var uri = new Uri(codebase, UriKind.Absolute);
return System.IO.Path.GetDirectoryName(uri.LocalPath) + "\\Resources\\config.xml";
}
}
publicoverridevoid LoadSettingsFromStorage() {
using (var sr = new StreamReader(Path, Encoding.UTF8)) {
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Store));
var config = (Store)xmlSerializer.Deserialize(sr);
this.Num = config.Num;
}
}
publicoverridevoid SaveSettingsToStorage() {
var config = new Store {
Num = this.Num
};
using (var sw = new StreamWriter(Path, false, Encoding.UTF8)) {
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Store));
xmlSerializer.Serialize(sw, config);
}
}
}
publicclass Store {
publicint Num { get; set; }
}
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.Win32;
using System.ComponentModel;
using System.IO;
using System.Text;
namespace TestDialog {
/// <summary>/// This is the class that implements the package exposed by this assembly./// </summary>/// <remarks>/// <para>/// The minimum requirement for a class to be considered a valid package for Visual Studio/// is to implement the IVsPackage interface and register itself with the shell./// This package uses the helper classes defined inside the Managed Package Framework (MPF)/// to do it: it derives from the Package class that provides the implementation of the/// IVsPackage interface and uses the registration attributes defined in the framework to/// register itself and its components with the shell. These attributes tell the pkgdef creation/// utility what data to put into .pkgdef file./// </para>/// <para>/// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file./// </para>/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[Guid(Dialog.PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[ProvideOptionPage(typeof(OptionDialog),"Test Dialog","General",0,0,true)]
publicsealedclass Dialog : Package {
/// <summary>/// Dialog GUID string./// </summary>publicconststring PackageGuidString = "3e22428e-3305-4a4b-9c3e-11c54c2bef28";
/// <summary>/// Initializes a new instance of the <seecref="Dialog"/> class./// </summary>public Dialog() {
// Inside this method you can place any initialization code that does not require// any Visual Studio service because at this point the package object is created but// not sited yet inside Visual Studio environment. The place to do all the other// initialization is the Initialize method.
}
#region Package Members/// <summary>/// Initialization of the package; this method is called right after the package is sited, so this is the place/// where you can put all the initialization code that rely on services provided by VisualStudio./// </summary>protectedoverridevoid Initialize() {
base.Initialize();
}
#endregion
}
publicclass OptionDialog : DialogPage {
[Category("かてごりー")]
[DisplayName("ひょうじめい")]
[Description("せつめい")]
publicint Num { get; set; }
publicstring Path {
get {
var codebase = typeof(Dialog).Assembly.CodeBase;
var uri = new Uri(codebase, UriKind.Absolute);
return System.IO.Path.GetDirectoryName(uri.LocalPath) + "\\Resources\\config.xml";
}
}
publicoverridevoid LoadSettingsFromStorage() {
using (var sr = new StreamReader(Path, Encoding.UTF8)) {
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Store));
var config = (Store)xmlSerializer.Deserialize(sr);
this.Num = config.Num;
}
}
publicoverridevoid SaveSettingsToStorage() {
var config = new Store {
Num = this.Num
};
using (var sw = new StreamWriter(Path, false, Encoding.UTF8)) {
var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Store));
xmlSerializer.Serialize(sw, config);
}
}
}
publicclass Store {
publicint Num { get; set; }
}
}
vsBuildScope 列挙型はリファレンスによると Represents the scope of the build. らしい。ふーんなるほどねすべて理解した。それとvsBuildAction列挙型は同リファレンスによるとRepresents the type of build action that is occurring, such as a build or a deploy action.らしい。なるほどなるほど
色々片付いたのでちょっとなんか作ろうと思って、いつもお世話になっておりますVisual Studioの拡張機能でも作ろうかとテンプレート使って作成したプロジェクトが・・・・ビルドできない・・・・!ビルドしたら「no resource file set the resource merger」ってだけ出て終わる・・・!つらい・・・!!!環境はVS2017Community 15.5.2