本文整理汇总了C#中MonoDevelop.Projects.Project.GetDefaultBuildAction方法的典型用法代码示例。如果您正苦于以下问题:C# Project.GetDefaultBuildAction方法的具体用法?C# Project.GetDefaultBuildAction怎么用?C# Project.GetDefaultBuildAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoDevelop.Projects.Project
的用法示例。
在下文中一共展示了Project.GetDefaultBuildAction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFilesToProject
/// <summary>
/// Adds files to a project, potentially asking the user whether to move, copy or link the files.
/// </summary>
public IList<ProjectFile> AddFilesToProject (Project project, FilePath[] files, FilePath[] targetPaths,
string buildAction)
{
Debug.Assert (project != null);
Debug.Assert (files != null);
Debug.Assert (targetPaths != null);
Debug.Assert (files.Length == targetPaths.Length);
AddAction action = AddAction.Copy;
bool applyToAll = true;
bool dialogShown = false;
IProgressMonitor monitor = null;
if (files.Length > 10) {
monitor = new MessageDialogProgressMonitor (true);
monitor.BeginTask (GettextCatalog.GetString("Adding files..."), files.Length);
}
var newFileList = new List<ProjectFile> ();
//project.AddFile (string) does linear search for duplicate file, so instead we use this HashSet and
//and add the ProjectFiles directly. With large project and many files, this should really help perf.
//Also, this is a better check because we handle vpaths and links.
//FIXME: it would be really nice if project.Files maintained these hashmaps
var vpathsInProject = new HashSet<FilePath> (project.Files.Select (pf => pf.ProjectVirtualPath));
var filesInProject = new Dictionary<FilePath,ProjectFile> ();
foreach (var pf in project.Files)
filesInProject [pf.FilePath] = pf;
using (monitor)
{
for (int i = 0; i < files.Length; i++) {
FilePath file = files[i];
if (monitor != null) {
monitor.Log.WriteLine (file);
monitor.Step (1);
}
if (FileService.IsDirectory (file)) {
//FIXME: warning about skipping?
newFileList.Add (null);
continue;
}
FilePath targetPath = targetPaths[i].CanonicalPath;
Debug.Assert (targetPath.IsChildPathOf (project.BaseDirectory));
var vpath = targetPath.ToRelative (project.BaseDirectory);
if (vpathsInProject.Contains (vpath)) {
if (project.Files.GetFileWithVirtualPath (vpath).FilePath != file)
MessageService.ShowWarning (GettextCatalog.GetString (
"There is a already a file or link in the project with the name '{0}'", vpath));
continue;
}
string fileBuildAction = buildAction;
if (string.IsNullOrEmpty (buildAction))
fileBuildAction = project.GetDefaultBuildAction (targetPath);
//files in the target directory get added directly in their current location without moving/copying
if (file.CanonicalPath == targetPath) {
AddFileToFolder (newFileList, vpathsInProject, filesInProject, file, fileBuildAction);
continue;
}
//for files outside the project directory, we ask the user whether to move, copy or link
AddExternalFileDialog addExternalDialog = null;
if (!dialogShown || !applyToAll) {
addExternalDialog = new AddExternalFileDialog (file);
if (files.Length > 1) {
addExternalDialog.ApplyToAll = applyToAll;
addExternalDialog.ShowApplyAll = true;
}
if (file.IsChildPathOf (targetPath.ParentDirectory))
addExternalDialog.ShowKeepOption (file.ParentDirectory.ToRelative (targetPath.ParentDirectory));
else {
if (action == AddAction.Keep)
action = AddAction.Copy;
addExternalDialog.SelectedAction = action;
}
}
try {
if (!dialogShown || !applyToAll) {
if (MessageService.RunCustomDialog (addExternalDialog) == (int) Gtk.ResponseType.Cancel) {
project.Files.AddRange (newFileList.Where (f => f != null));
return newFileList;
}
action = addExternalDialog.SelectedAction;
applyToAll = addExternalDialog.ApplyToAll;
dialogShown = true;
}
//.........这里部分代码省略.........
示例2: AddFilesToProject
/// <summary>
/// Adds files to a project, potentially asking the user whether to move, copy or link the files.
/// </summary>
public IList<ProjectFile> AddFilesToProject (Project project, FilePath[] files, FilePath[] targetPaths,
string buildAction)
{
Debug.Assert (project != null);
Debug.Assert (files != null);
Debug.Assert (targetPaths != null);
Debug.Assert (files.Length == targetPaths.Length);
AddAction action = AddAction.Copy;
bool applyToAll = true;
bool dialogShown = false;
bool supportsLinking = !(project is MonoDevelop.Projects.SharedAssetsProjects.SharedAssetsProject);
var confirmReplaceFileMessage = new QuestionMessage ();
if (files.Length > 1) {
confirmReplaceFileMessage.AllowApplyToAll = true;
confirmReplaceFileMessage.Buttons.Add (new AlertButton (GettextCatalog.GetString ("Skip")));
}
confirmReplaceFileMessage.Buttons.Add (AlertButton.Cancel);
confirmReplaceFileMessage.Buttons.Add (AlertButton.OverwriteFile);
confirmReplaceFileMessage.DefaultButton = confirmReplaceFileMessage.Buttons.Count - 1;
ProgressMonitor monitor = null;
if (files.Length > 10) {
monitor = new MessageDialogProgressMonitor (true);
monitor.BeginTask (GettextCatalog.GetString("Adding files..."), files.Length);
}
var newFileList = new List<ProjectFile> ();
//project.AddFile (string) does linear search for duplicate file, so instead we use this HashSet and
//and add the ProjectFiles directly. With large project and many files, this should really help perf.
//Also, this is a better check because we handle vpaths and links.
//FIXME: it would be really nice if project.Files maintained these hashmaps
var vpathsInProject = new Dictionary<FilePath, ProjectFile> ();
var filesInProject = new Dictionary<FilePath,ProjectFile> ();
foreach (var pf in project.Files) {
filesInProject [pf.FilePath] = pf;
vpathsInProject [pf.ProjectVirtualPath] = pf;
}
using (monitor)
{
for (int i = 0; i < files.Length; i++) {
FilePath file = files[i];
if (monitor != null) {
monitor.Log.WriteLine (file);
monitor.Step (1);
}
if (FileService.IsDirectory (file)) {
//FIXME: warning about skipping?
newFileList.Add (null);
continue;
}
FilePath targetPath = targetPaths[i].CanonicalPath;
Debug.Assert (targetPath.IsChildPathOf (project.BaseDirectory));
ProjectFile vfile;
var vpath = targetPath.ToRelative (project.BaseDirectory);
if (vpathsInProject.TryGetValue (vpath, out vfile)) {
if (vfile.IsLink) {
MessageService.ShowWarning (GettextCatalog.GetString (
"There is already a link in the project with the name '{0}'", vpath));
continue;
} else if (vfile.FilePath == file) {
// File already exists in project.
continue;
}
}
string fileBuildAction = buildAction;
if (string.IsNullOrEmpty (buildAction))
fileBuildAction = project.GetDefaultBuildAction (targetPath);
//files in the target directory get added directly in their current location without moving/copying
if (file.CanonicalPath == targetPath) {
if (vfile != null)
ShowFileExistsInProjectMessage (vpath);
else
AddFileToFolder (newFileList, vpathsInProject, filesInProject, file, fileBuildAction);
continue;
}
//for files outside the project directory, we ask the user whether to move, copy or link
AddExternalFileDialog addExternalDialog = null;
if (!dialogShown || !applyToAll) {
addExternalDialog = new AddExternalFileDialog (file);
if (!supportsLinking)
addExternalDialog.DisableLinkOption ();
if (files.Length > 1) {
addExternalDialog.ApplyToAll = applyToAll;
//.........这里部分代码省略.........
示例3: AddFileToProject
public ProjectFile AddFileToProject (SolutionItem policyParent, Project project, string language, string directory, string name)
{
generatedFile = SaveFile (policyParent, project, language, directory, name);
if (generatedFile != null) {
string buildAction = this.buildAction ?? project.GetDefaultBuildAction (generatedFile);
ProjectFile projectFile = project.AddFile (generatedFile, buildAction);
if (!string.IsNullOrEmpty (dependsOn)) {
Dictionary<string,string> tags = new Dictionary<string,string> ();
ModifyTags (policyParent, project, language, name, generatedFile, ref tags);
string parsedDepName = StringParserService.Parse (dependsOn, tags);
if (projectFile.DependsOn != parsedDepName)
projectFile.DependsOn = parsedDepName;
}
if (!string.IsNullOrEmpty (customTool))
projectFile.Generator = customTool;
DotNetProject netProject = project as DotNetProject;
if (netProject != null) {
// Add required references
foreach (string aref in references) {
string res = netProject.AssemblyContext.GetAssemblyFullName (aref, netProject.TargetFramework);
res = netProject.AssemblyContext.GetAssemblyNameForVersion (res, netProject.TargetFramework);
if (!ContainsReference (netProject, res))
netProject.References.Add (new ProjectReference (ReferenceType.Package, aref));
}
}
return projectFile;
} else
return null;
}
示例4: AddFilesToProject
/// <summary>
/// Adds files to a project, potentially asking the user whether to move, copy or link the files.
/// </summary>
public IList<ProjectFile> AddFilesToProject (Project project, FilePath[] files, FilePath[] targetPaths,
string buildAction)
{
Debug.Assert (project != null);
Debug.Assert (files != null);
Debug.Assert (targetPaths != null);
Debug.Assert (files.Length == targetPaths.Length);
int action = -1;
IProgressMonitor monitor = null;
if (files.Length > 10) {
monitor = new MessageDialogProgressMonitor (true);
monitor.BeginTask (GettextCatalog.GetString("Adding files..."), files.Length);
}
var newFileList = new List<ProjectFile> ();
//project.AddFile (string) does linear search for duplicate file, so instead we use this HashSet and
//and add the ProjectFiles directly. With large project and many files, this should really help perf.
//Also, this is a better check because we handle vpaths and links.
//FIXME: it would be really nice if project.Files maintained these hashmaps
var vpathsInProject = new HashSet<FilePath> (project.Files.Select (pf => pf.ProjectVirtualPath));
var filesInProject = new Dictionary<FilePath,ProjectFile> ();
foreach (var pf in project.Files)
filesInProject [pf.FilePath] = pf;
using (monitor)
{
for (int i = 0; i < files.Length; i++) {
FilePath file = files[i];
if (monitor != null) {
monitor.Log.WriteLine (file);
monitor.Step (1);
}
if (FileService.IsDirectory (file)) {
//FIXME: warning about skipping?
newFileList.Add (null);
continue;
}
FilePath targetPath = targetPaths[i].CanonicalPath;
Debug.Assert (targetPath.IsChildPathOf (project.BaseDirectory));
var vpath = targetPath.ToRelative (project.BaseDirectory);
if (vpathsInProject.Contains (vpath)) {
MessageService.ShowWarning (GettextCatalog.GetString (
"There is a already a file or link in the project with the name '{0}'", vpath));
continue;
}
string fileBuildAction = buildAction;
if (string.IsNullOrEmpty (buildAction))
fileBuildAction = project.GetDefaultBuildAction (file);
//files in the target directory get added directly in their current location without moving/copying
if (file.CanonicalPath == targetPath) {
//FIXME: MD project system doesn't cope with duplicate includes - project save/load will remove the file
ProjectFile pf;
if (filesInProject.TryGetValue (targetPath, out pf)) {
var link = pf.Link;
MessageService.ShowWarning (GettextCatalog.GetString (
"The link '{0}' in the project already includes the file '{1}'", link, file));
continue;
}
pf = new ProjectFile (file, fileBuildAction);
vpathsInProject.Add (pf.ProjectVirtualPath);
filesInProject [pf.FilePath] = pf;
newFileList.Add (pf);
continue;
}
//for files outside the project directory, we ask the user whether to move, copy or link
var md = new Gtk.MessageDialog (
IdeApp.Workbench.RootWindow,
Gtk.DialogFlags.Modal | Gtk.DialogFlags.DestroyWithParent,
Gtk.MessageType.Question, Gtk.ButtonsType.None,
GettextCatalog.GetString ("The file {0} is outside the target directory. What would you like to do?", file));
try {
Gtk.CheckButton remember = null;
if (files.Length > 1) {
remember = new Gtk.CheckButton (GettextCatalog.GetString ("Use the same action for all selected files."));
md.VBox.PackStart (remember, false, false, 0);
}
const int ACTION_LINK = 3;
const int ACTION_COPY = 1;
const int ACTION_MOVE = 2;
md.AddButton (GettextCatalog.GetString ("_Link"), ACTION_LINK);
md.AddButton (Gtk.Stock.Copy, ACTION_COPY);
md.AddButton (GettextCatalog.GetString ("_Move"), ACTION_MOVE);
md.AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
md.VBox.ShowAll ();
//.........这里部分代码省略.........