我有一个Assembly,其中包含BuildAction = Content和Copy to output = Always的文件。现在我构建依赖于Assembly的Executable,并且我希望VisualStudio/MsBuild以某种方式复制内容文件以便输出,以便Assembly能够工作。但它没有发生。BuildAction =内容递归
目前,我手动解决此问题:通过将这些文件添加为可执行文件项目的链接或在构建事件中进行复制。有没有办法以自动的方式解决这个问题?
我有一个Assembly,其中包含BuildAction = Content和Copy to output = Always的文件。现在我构建依赖于Assembly的Executable,并且我希望VisualStudio/MsBuild以某种方式复制内容文件以便输出,以便Assembly能够工作。但它没有发生。BuildAction =内容递归
目前,我手动解决此问题:通过将这些文件添加为可执行文件项目的链接或在构建事件中进行复制。有没有办法以自动的方式解决这个问题?
如果您手动编辑代表项目的.csproj文件,则可以完成此操作。例如,假设您有一个名为“二进制文件”的文件夹,您需要将其复制到输出目录(我建议使用None的构建操作并始终复制到输出目录,但此方法可以适用于任一种,正如我将在下面显示)。:
关闭visual studio,没有任何“二进制文件”文件或文件夹添加。在Windows资源管理器中,浏览到您的项目目录,并手动创建这个“二进制文件”文件夹和所需的文件。然后,使用文本编辑器编辑项目的.csproj文件。用几个“ItemGroup”标签查找文件的一部分。你会想使这个此外:当你再次打开Visual Studio中的项目
<ItemGroup>
<None Include="binaries\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
,你会发现你的包裹用正确的生成操作和复印设置。
同样可以与内容生成操作来完成,而不是:
<ItemGroup>
<Content Include="binaries\**\*.*" />
</ItemGroup>
不过,我已经在野外使用此却不太顺利。
这是另一种答案,解决这个问题:
Is there a way to automatically include content files into asp.net project file?
//this is the class library project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ClassLibrary1
{
public class Class1
{
public Class1()
{
string res = "";
using (StreamReader sr = new StreamReader("TextFile1.txt"))
{
res = sr.ReadToEnd();
}
Console.WriteLine("ok dll {0}",res);
Console.ReadLine();
}
}
}
//I add a text file which name is TextFile1.txt with BuildAction = Content and Copy to output = //Always
//it contains a sentence
i am in the file no problem
//a console application that refers the class library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using ClassLibrary1;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Class1 c = new Class1();
}
}
}
//it is ok, with a rebuild all if you update the text file...
您可以将BuildAction的改变EmbeddedResource,这样它的大会中,你可以很容易地访问它。
是否绝对有必要保持BuildAction = Content? – MAXE 2012-08-28 07:42:56
@MAXE,我不确定...这是什么想法? – SiberianGuy 2012-08-28 07:46:58
尝试清理整个解决方案并重建所有内容:我尝试在我的机器上运行,但没有问题(在WPF解决方案中)。这可能在MSDN上:查看http://msdn.microsoft.com/en-us/library/aa970494(v=vs.100).aspx#Content_Files的“内容文件”部分 – MAXE 2012-08-28 07:54:21