我有一个 Powershell 模块,如下所示:
function SayHello
{
echo "hello"
}
Run Code Online (Sandbox Code Playgroud)
我将其另存为say-hello.psm1并将其添加到 dockerfile 中,如下所示:
COPY --chmod=0755 say-hello.psm1 /root/.local/share/powershell/Modules/say-hello.psm1
Run Code Online (Sandbox Code Playgroud)
当我启动 docker 映像并运行时,SayHello它告诉我它找不到命令:
但是,如果我随后运行 Import-Module 命令并重试,它会起作用:
我想也许我有错误的文件夹,但是当我运行时,$Env:PSModulePath我得到了/root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules. 根据文档,这就是模块应该放置的位置。(我把它放在第一个)
我需要做什么才能让我的 powershell 模块工作而无需手动导入?
我正在尝试设置我的安装,以使用WIX为我的站点配置其证书.
我可以在IIS中查看证书并可以访问.cer文件.这就是我所知道的所有证书,所以请愚蠢地回答任何答案.(即我不知道我的"BinaryKey"是什么).
证书已安装在计算机上.理想情况下,我想在wix中配置一种方法来配置要使用的已安装证书.如果有人知道该怎么做,请在这里发布!
如果无法做到,那么我想要一个如何安装(也许卸载)证书的好例子.
感谢您的所有答案.
Vaccano
我有一个网站,其中有一堆预先创建并存放在网络服务器上的PDF.
我不想让用户只输入一个URL并获取PDF文件(即http://MySite/MyPDFFolder/MyPDF.pdf)
我想只允许在加载它们并显示它们时查看它们.
我之前做过类似的事.我使用PDFSharp在内存中创建PDF,然后将其加载到这样的页面:
protected void Page_Load(object sender, EventArgs e)
{
try
{
MemoryStream streamDoc = BarcodeReport.GetPDFReport(ID, false);
// Set the ContentType to pdf, add a header for the length
// and write the contents of the memorystream to the response
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", Convert.ToString(streamDoc.Length));
Response.BinaryWrite(streamDoc.ToArray());
//End the response
Response.End();
streamDoc.Close();
}
catch (NullReferenceException)
{
Communication.Logout();
}
}
Run Code Online (Sandbox Code Playgroud)
我试图使用此代码从文件中读取,但无法弄清楚如何让MemoryStream读取文件.
我还需要一种方法来说"/ MyPDFFolder"路径是不可浏览的.
谢谢你的任何建议
我必须通过串口进行通信.我现在正尝试通过2个设备进行蓝牙通信,而且无处可去.
我在设备上有一个应用程序(称为蓝牙资源管理器),允许我进行串行通信,它将通过蓝牙发送,使用Stonestreet One堆栈,以防你想知道:(
在设置中,我可以创建一个定义了COM端口的"服务".
然后我尝试运行以下代码(我在一台设备上调用Write,在另一台设备上调用Read).BTExplorer在serialPort.Open()执行时启动配对应用程序.在那里我选择我想要使用的"服务"(串行端口1).
但是serialPort.ReadLine()挂起并且永远不会回来.(我的意思是真的挂起.我必须热启动设备来杀死我的应用程序.结束进程/终止进程不起作用.)
以下是供参考的代码:
public void WriteSerial()
{
SerialPort serialPort = new SerialPort("COM4");
serialPort.Open();
serialPort.WriteLine("Hello To The Other Side");
serialPort.Close();
}
public void ReadSerial()
{
SerialPort serialPort = new SerialPort("COM4");
serialPort.Open();
string output = serialPort.ReadLine();
serialPort.Close();
MessageBox.Show(output);
}
private void btnWrite_Click(object sender, EventArgs e)
{
WriteSerial();
}
private void btnRead_Click(object sender, EventArgs e)
{
ReadSerial();
}
Run Code Online (Sandbox Code Playgroud)
如何使这个工作?
我正在使用带有MC70设备的Windows Mobile 5.蓝牙堆栈是Stonestreet One(遗憾的是不能改变).在C#Compact Framework .NET 3.5中开发
这就是我今天在编码中看到的好奇心.
以下是示例代码:
public class SomeClass
{
public IUtils UtilitiesProperty { get; set; }
}
public interface IUtils
{
void DoSomething();
}
public class Utils : IUtils
{
void DoSomething();
}
Run Code Online (Sandbox Code Playgroud)
编译好了.
什么是UtilitiesProperty?它是一个Util?如果不止一个班级实施了IUTil怎么办?它会在编译失败吗?
我有一个Dictionary<string, FieldDefinition>依赖属性,当我将它绑定到WPF列表框时,我希望它只打印字符串(而不是FieldDefinition).
有没有办法做到这一点?
我有一个列表框,当选择或取消选择项目时,我想将更改保存到xml文件(因此它始终是文件的最新版本,用户不需要"保存"按钮).
在测试时我偶尔会遇到这个IOException:
该进程无法访问文件"C:\ MyPath\MyFile.xml",因为它正由另一个进程使用.
这是我的XML序列化代码:
// Save an object out to the disk
public static void SerializeObject<T>(this T toSerialize, String filename)
{
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
TextWriter textWriter = new StreamWriter(filename);
xmlSerializer.Serialize(textWriter, toSerialize);
}
// Load an object from the disk
private static T DeserialzeObject<T>(String filename) where T : class
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
try
{
TextReader textReader = new StreamReader(filename);
return (T)xmlSerializer.Deserialize(textReader);
}
catch (FileNotFoundException)
{ }
return null;
}
Run Code Online (Sandbox Code Playgroud)
以下是它的调用方式:
// Save off the list …Run Code Online (Sandbox Code Playgroud) 昨晚我的Visual Studio工作正常.今天它无法连接到互联网(无法下载RSS源或连接到我的TFS服务器).
我的互联网连接工作正常(我用它来写这个).
什么可能导致这个?是否有我可以解决的设置?
我唯一的线索是,Resharper给了我一些奇怪的错误.
System.ArgumentException: Invalid XML. Missing required tag for type 'System.Security.Policy.PolicyStatement'. System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for system.net/settings: Invalid XML. Missing required tag for type 'System.Security.Policy.PolicyStatement'. (C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.Config line 155) ---> System.ArgumentException: Invalid XML. Missing required tag for type 'System.Security.Policy.PolicyStatement'.
我检查了它提到的文件(devenv.exe.Config),它与没有问题的同事一样.
我尝试过的事情:
任何意见,将不胜感激.
更多信息:
当我尝试连接到我的TFS服务器时,出现此错误:
TF31001: Team Foundation cannot retrieve the list of team projects from Team Foundation Server MyTFSServer. The Team Foundation Server …
我正在查看BackgroundWorker.ReportProgress方法.它可以采用1个参数(int)或两个参数(int,object).
如果我想像这样分配ReportProgress:
var ReportProgressMethod = backgroundWorker.ReportProgress;
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,说有一个模糊的引用,因为(当然)该方法可以采取参数集.
如何更改上述语句以表示我想使用int, object该方法的版本.
(这背后的想法是我想将ReportProgressMethod作为参数传递给方法.)
我试图想出一个树遍历的算法,但我卡住了.
这是一个相当难的问题(与我提出的其他问题相比),所以我可能需要继续自己计算.但我想我会把它扔出去.
我有以下类结构:
public class Transition
{
// The state we are moving from.
public String From { get; set; }
// All the To states for this from
public List<String>To { get; set; }
}
List<Transition> currentTransistions;
Run Code Online (Sandbox Code Playgroud)
当currentTransistions完全填写时,它看起来像这样(对我来说):
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfTransition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Transition>
<From />
<To>
<string>Not Done</string>
</To>
</Transition>
<Transition>
<From>Not Done</From>
<To>
<string>In Progress</string>
<string>Deleted</string>
</To>
</Transition>
<Transition>
<From>Deleted</From>
<To>
<string>Not Done</string>
</To>
</Transition>
<Transition>
<From>In Progress</From>
<To>
<string>Done</string>
<string>Ready For Test</string>
<string>Deleted</string>
</To>
</Transition> …Run Code Online (Sandbox Code Playgroud)