|
i have been using cliwrap for running git commands and passing the arguments. But it seems to have failed while running my msbuild command from my c# console application.
What i am trying-
var stdOutSetup = new StringBuilder();
var stdErrSetup = new StringBuilder();
var Setup = await Cli.Wrap("msbuild")
.WithArguments("/t:scmclean && /t:setup")
.WithStandardOutputPipe(PipeTarget.ToStringBuilder(stdOutSetup))
.WithStandardErrorPipe(PipeTarget.ToStringBuilder(stdErrSetup))
.ExecuteBufferedAsync();
var stdOut2 = stdOutSetup.ToString();
var stdErr2 = stdErrSetup.ToString();
Console.WriteLine("Build Commands Output :");
Console.WriteLine(stdOut2);
Console.WriteLine(stdErr2);
is there any possible way where i can run msbuild commands from my c# console application?
|
|
|
|
|
Yes, you just have to supply the correct command line to run MsBuild. You don't say what the error is that you're getting back, and that's really important when troubleshooting problems.
My guess is going to be you're not supplying the path to MsBuild and/or you're not supplying any required command line parameters for it to know what you want to do.
AND STOPP SPAMMING THE SITE WITH THE SAME QUESTION OVER AND OVER AGAIN!
|
|
|
|
|
Open a console window that represents the OS shell (console) that your command is supposed to be running in. Open in the root directory.
Then type the following. It will fail I am sure. It will not work in your program until you can get it to run from the shell.
msbuild /t:scmclean && /t:setup
I did not investigate it too much but I am rather certain that however you are doing it (which shell) that that '&&' is wrong.
|
|
|
|
|
I have tried running msbuild /t:scmclean from my command prompt, it works fine , but when i try to call the same command from my c# console application using the code below
namespace BuildCode
{
class BuildCM
{
public static void Main()
{
Process msetup = new Process();
msetup.StartInfo.FileName = "cmd.exe";
msetup.StartInfo.CreateNoWindow = true;
msetup.StartInfo.RedirectStandardInput = true;
msetup.StartInfo.RedirectStandardOutput = true;
msetup.StartInfo.UseShellExecute = false;
msetup.Start();
msetup.StandardInput.WriteLine("msbuild.exe D:\\git\\btf_pi_testrack\\Build\\Tools /t:scmclean");
msetup.StandardInput.Flush();
msetup.StandardInput.Close();
msetup.WaitForExit();
Console.WriteLine(msetup.StandardOutput.ReadToEnd());
Console.ReadKey();
}
}
}
i get an error:
C:\Users\JediAdmin\source\repos\msbuild\bin\Debug\net7.0>msbuild.exe D:\git\btf_pi_testrack\Build\Tools /t:scmclean
MSBuild version 17.4.0+18d5aef85 for .NET
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file., it fails to run msbuild command for the particular directory
but if i execute msbuild.exe D:\git\btf_pi_testrack\Build\Tools /t:scmclean in command prompt, it works fine.
Also i did a little bit of digging for this issue and came back with Microsoft.Build.Runtime and Microsoft.Build.utilities.core for running msbuild commands from console application, however i couldn't get any code example to understabd how it does that? any idea on this as well?
|
|
|
|
|
Madhurima Dutta wrote: msbuild /t:scmclean
First I doubt it ran find from the root directory.
Second that is not the command that you are attempting to run in the code you originally posted.
Third what you posted here does not match what msbuild documentation expects.
MSBuild Command-Line Reference - MSBuild | Microsoft Learn[^]
|
|
|
|
|
This is Model Class
public class CartInfo
{
[Key]
public int S_NO { get; set; }
public virtual int Bill_Id { get; set; }
public virtual int Ship_Id { get; set; }
public virtual int Product_Id { get; set; }
[ForeignKey("Product_Id")]
public List<Products> Products { get; set; }
public int Sub_Total { get; set; }
public int Product_Quantity { get; set; }
}
[Table("Product_Detail")]
public class Products
{
[Key, Column(Order = 0)]
public int Product_Id { get; set; }
public string Product_Code { get; set; }
public string Product_Name { get; set; }
public int Unit_Price { get; set; }
}
Insert command
string code = (model.Cart[i]).Products[0].Product_Code;
var _products = (from p in db.Products where p.Product_Code ==code select p).FirstOrDefault();
int Product_Id = _products.Product_Id;
CartInfo cart = new CartInfo();
cart.Bill_Id = Bill_Id;
cart.Ship_Id = Ship_Id;
cart.Product_Id = Product_Id;
cart.Products = new List<Products>();
var pf = new Products();
pf.Product_Code = (model.Cart[i]).Products[0].Product_Code;
pf.Product_Name = (model.Cart[i]).Products[0].Product_Name;
pf.Unit_Price = (model.Cart[i]).Products[0].Unit_Price;
cart.Products.Add(pf);
cart.Product_Quantity = (model.Cart[i]).Product_Quantity;
cart.Sub_Total = (model.Cart[i]).Sub_Total;
db.Cart_Details.Add(cart); <big></big>
db.SaveChanges();
|
|
|
|
|
The exception says you can't put a product where a list of products is expected. CartInfo specifies it as a list of products.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
A "Product" is single; products is plural.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I have extended a class from ListCollectionView for Data Virtualizing. I am able to load after taking reference from this article - Data Virtualization using DataGrid[^] but I am not able to add GroupDescriptions in DataGrid.
Please suggest, what I need to do?
|
|
|
|
|
Don't post this under generic forums - if you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I did that but not yet received answer so posting here.
|
|
|
|
|
You won't get much help regarding a specific article here. We'd have to read it before answering.
That sounds lazy.. We're volunteers answering questions, and questions that require to read an entire article are skipped. If you reformulate your question to the problem you're trying to solve may help, as well as a piece of code and/or the message of any exceptions.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
As Freddie has intimated by handing you the business, but not actually saying anything useful, you have to insult the article poster in such a way as to get his goad. That way he'll have to defend his code by further describing some cloudy aspect of it. With any luck, something he adds then will be of use to you.
My experience with article writers is that stroking their sense of entitlement for a couple of years can't do any harm. The side effect of this active participation, your part (especially if you haven't posted a tip/trick/article ... yet) is they get to know you. Sure, you have to be able to dodge interpretive criticism but, hey!
It's only a couple of years. Think of it this way. There's plenty of other stuff her on CP to browse and fill the up the time.
|
|
|
|
|
I´m trying to take the entire datatable with its values to postgresql but I seem to do something wrong. Code is as follows:
foreach (DataRow row in dt_IS.Rows)
{
using (NpgsqlCommand cmdCopy = new NpgsqlCommand("INSERT INTO " + Table + " VALUES(@num1));", Conn))
{
object num1 = row.Table.Rows[0][0].ToString();
cmdCopy.Parameters.AddWithValue("@num1", num1);
Conn.Open();
cmdCopy.ExecuteNonQuery();
Conn.Close();
}
}
|
|
|
|
|
(One problem is that) You're creating a new connection for every row in the data table.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
However that idiom is certainly something that could run. It is just not optimal.
|
|
|
|
|
Depends on your definition of "run" and "certain". Different standards obviously.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Well, first, you're creating a new command and parameter for every record in the table. You don't need to do that and not doing it will improve performance.
Next, for every row in your Rows collection, you're treating each row as if it has a table itself, and only every looking at the first row and column of that table, no matter which record you're looking at. This makes no sense at all.
Lastly, you're only every inserting a single value per row into your new table. Is this correct? What is the datatype of the values you're sending to the new table? What datatype does the new table expect for that value? For example, you cannot send a string to a column that is expecting numbers, either integers or decimal values.
|
|
|
|
|
In addition to the comments by others, you are ignoring the value returned by the call to ExecuteNonQuery , so you have no idea if it succeeded or not.
|
|
|
|
|
Member 14103987 wrote: but I seem to do something wrong.
It would help if you explained why it is 'wrong'. Is there an error? Or does the data just not show up.
Your code is attempting to insert one value into a table one row at a time. That will only work if the table only has one column. You can insert just one value, depending on how the table is created, but in that case your 'Insert' must define that column. The form would look like the following
Insert into MyTable (MyRow1) values(1)
And your code does not have the '(MyRow1)' part.
Second possibility is that because you say 'ToString()' that means the type of num1 is a String. Exactly as you requested.
But because you named it 'num1' it seems likely that you actually want a number. And very possible that AddWithValue() is then translating that to a string value for the database. So if your 'MyRow1' is a database type of 'int' but your code is creating the following, because 'num1' is a string, it will not work. (Notice the ticks around the number.)
Insert into MyTable values('1')
|
|
|
|
|
Thanks for the suggestions. Here is an update that would explain everything in more detail.
I have a datatable with values, the first column will always be a string and the rest (5 columns) will have numbers. I have used the code that I shared to make it work for a datagridview but now I want to make it work for a datatable . The way I though was best was to take each row into the postgresql server and store it until its needed later. It seems like a sqladapter seems to be a better way to handle this and therefore I had some help trying to figure this out with the following code:
using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter("SELECT num1, num2, num3, num4, num5, num6 FROM " + Table + ";", Conn))
{
NpgsqlCommand insert = new NpgsqlCommand("INSERT INTO " + Table + " VALUES (@num1, @num2, @num3, @num4, @num5, @num6);", Conn);
insert.Parameters.Add("@num1", NpgsqlDbType.Text, 200, "1");
insert.Parameters.Add("@num2", NpgsqlDbType.Text, 50, "2");
insert.Parameters.Add("@num3", NpgsqlDbType.Text, 50, "3");
insert.Parameters.Add("@num4", NpgsqlDbType.Text, 50, "4");
insert.Parameters.Add("@num5", NpgsqlDbType.Text, 50, "5");
insert.Parameters.Add("@num6", NpgsqlDbType.Text, 50, "6");
adapter.InsertCommand = insert;
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable table = new DataTable();
adapter.FillSchema(table, SchemaType.Source);
DataRow row = table.NewRow();
row["1"] = row.Table.Rows[0][0].ToString();
row["2"] = row.Table.Rows[0][1].ToString();
row["3"] = row.Table.Rows[0][2].ToString();
row["4"] = row.Table.Rows[0][3].ToString();
row["5"] = row.Table.Rows[0][4].ToString();
row["6"] = row.Table.Rows[0][5].ToString();
table.Rows.Add(row);
adapter.Update(table);
}
}
The code seems to work until the actual strings/values need to be put inside the SQL server table(see inside of code to know where the code breaks out). If anyone knows how to make the code work or is willing to show whats missing I would gladly appreciate it.
|
|
|
|
|
If the last 5 columns are numbers, why is your parameter code treating them all as strings?
|
|
|
|
|
Providing the details of the exception would have helped!
Member 14103987 wrote:
DataTable table = new DataTable(); That creates a new empty DataTable , with no rows.
Member 14103987 wrote:
adapter.FillSchema(table, SchemaType.Source); That configures the columns of the table. There are still no rows in the table.
Member 14103987 wrote:
DataRow row = table.NewRow(); That creates a new row with the same schema as the table. There are still no rows in the table.
Member 14103987 wrote:
row.Table.Rows[0][0] This attempts to retrieve the value of the first column of the first row of a table with no rows.
Unsurprisingly, this throws an IndexOutOfRangeException with the message "There is no row at position 0."
You cannot copy data that doesn't exist from an empty DataTable to itself. You need to work out precisely where the source data is stored, and copy from that instead.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello, Profs
Please, I need help in my c# journal code as I find it difficult to get rid of the errors.
Below is the sample of my c# code and I will appreciate if the errors could be fixed.
Thanks.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace Journal
{
class Program
{
static void Main(string[] args)
{
Journal journal = new Journal();
while (true)
{
Console.WriteLine("1. Write a new entry");
Console.WriteLine("2. Display journal");
Console.WriteLine("3. Save journal");
Console.WriteLine("4. Load journal");
Console.WriteLine("5. Quit");
Console.Write("Enter your choice: ");
int userChoice = Convert.ToInt32(Console.ReadLine());
if (userChoice == 1)
{
string chosenPrompt = journal.GetRandomPrompt();
Console.WriteLine("Prompt: " + chosenPrompt);
Console.WriteLine("Write your response:");
string response = Console.ReadLine();
Entry newEntry = new Entry
{
Date = DateTime.Now,
Prompt = chosenPrompt,
Response = response
};
journal.AddEntry(newEntry);
}
else if (userChoice == 2)
{
journal.DisplayEntries();
}
else if (userChoice == 3)
{
Console.WriteLine("Enter a filename to save journal:");
string filename = Console.ReadLine();
journal.SaveJournal(filename);
}
else if (userChoice == 4)
{
Console.WriteLine("Enter a filename to load journal:");
string filename = Console.ReadLine();
journal.LoadJournal(filename);
}
else if (userChoice == 5)
{
break;
}
else
{
Console.WriteLine("Invalid choice. Try again.");
}
}
}
}
class Entry
{
public DateTime Date { get; set; }
public string Prompt { get; set; }
public string Response { get; set; }
}
class Journal
{
private List<string> prompts = new List<string>
{
"What did you learn today?",
"What are you grateful for?",
"What did you accomplish today?",
"What challenges did you face today?",
"What are your goals for tomorrow?"
};
private List<Entry> entries = new List<Entry>();
public string GetRandomPrompt()
{
Random rand = new Random();
int index = rand.Next(prompts.Count);
return prompts[index];
}
public void AddEntry(Entry entry)
{
entries.Add(entry);
}
public void DisplayEntries()
{
Console.WriteLine("Journal Entries:");
foreach (Entry entry in entries)
{
Console.WriteLine("Date: " + entry.Date);
Console.WriteLine("Prompt: " + entry.Prompt);
Console.WriteLine("Response: " + entry.Response);
Console.WriteLine("----------------");
}
}
public void SaveJournal(string filename)
{
using (Stream stream = File.Open(filename, FileMode.Create))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, entries);
}
}
public void LoadJournal(string filename)
{
if (File.Exists(filename))
{
using (Stream stream = File.Open(filename, FileMode.Open))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
entries = (List<Entry>)binaryFormatter.Deserialize(stream);
}
}
else
{
Console.WriteLine("File does not exist.");
}
}
}
}
|
|
|
|
|
Just dumping 137 lines of unexplained code and demanding that we "fix the errors" is unacceptable.
If you can't be bothered to explain precisely what the errors are, what you have tried, and where you are stuck, then you're not getting any help.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|