当我在 TFS 中排队新构建时,我可以在我的项目目录中保留文件夹的内容吗?
Can I preserve a folder's contents in my project directory when I queue a new Build in TFS?
我有问题。我正在使用 Team Foundation Server 2017 RTM。我有一个构建定义,它将我的应用程序部署到开发服务器 运行 Windows Server 2012 R2。我的应用程序允许用户上传图像和 PDF。完成后,将在我的项目的根目录中创建一个名为 Media 的文件夹,并将文件上传到此处。问题是,每当我对一个新版本进行排队时,这个文件夹就会被破坏,所有指向媒体的链接都不会指向任何东西。我在管理和设置 TFS 方面相当陌生,所以我想知道每当我对新构建进行排队时,是否有任何方法可以保留我的媒体文件夹的内容。有任何想法吗?
根据您的描述,构建代理中有工作目录的概念。如果您在构建定义中 set clean=true ,这将在您查询新构建时删除以前的构建输出。不确定您的媒体文件夹位于何处,请避免将其 create/put 放在构建代理的某些目录中,例如 Build.ArtifactStagingDirectory
The local path on the agent where any artifacts are copied to before
being pushed to their destination. For example: c:\agent_work\a.
A typical way to use this folder is to publish your build artifacts
with the Copy files and Publish build artifacts steps.
Note: This directory is purged before each new build, so you don't have to clean it up yourself.
更多关于build/release中文件夹路径的详细信息,您可以参考这个教程--Predefined variables
好的,所以我花了一整天的时间看着这个。
在我的 C# 代码中,我创建了一个目录,如下所示:
// -- Create a new file name that is unique
string fileExtension = Path.GetExtension(upload.FileName);
Guid fileGuid = Guid.NewGuid();
string fileName = fileGuid + fileExtension;
// -- Create the directory and upload the image to that directory
string mediaDirectory = Server.MapPath("~/Media/");
Directory.CreateDirectory(mediaDirectory);
string filePath = Path.Combine(mediaDirectory, fileName);
upload.SaveAs(filePath);
然后我会在媒体对象上设置图像 url,例如:
string imageUrl = "/Media/" + fileName;
所以现在,我没有将图像存储在数据库中,而是将 URL 存储到图像中。
这是在我可以存储文件的应用程序目录中创建的目录:
这很酷,但正如我提到的,每次我对新构建进行排队时,这个目录都会被销毁。我解决这个问题的方法是修改我存储图像的位置:
// -- Create a new file name that is unique
string fileExtension = Path.GetExtension(upload.FileName);
Guid fileGuid = Guid.NewGuid();
string fileName = fileGuid + fileExtension;
// -- Create the directory and upload the image to that directory
// The Media directory will be created on the C drive root
string mediaDirectory = @"c:\Media";
Directory.CreateDirectory(mediaDirectory);
string filePath = Path.Combine(mediaDirectory, fileName);
upload.SaveAs(filePath);
现在,我的 Media 文件夹已创建在服务器的 C 驱动器上,并且不会在我对新构建进行排队时被破坏。由于该应用程序无法访问应用程序目录之外的文件,因此我需要一种方法来访问 Media 目录中的这些文件。我所做的是在 IIS 中创建一个指向 Media 文件夹的新虚拟文件夹,并为其指定别名 Media:
现在我可以访问我放在 Media 目录中的所有文件,并在需要时正确显示图像。我真的希望这对某人有帮助,因为我花了太长时间看这个。
我有问题。我正在使用 Team Foundation Server 2017 RTM。我有一个构建定义,它将我的应用程序部署到开发服务器 运行 Windows Server 2012 R2。我的应用程序允许用户上传图像和 PDF。完成后,将在我的项目的根目录中创建一个名为 Media 的文件夹,并将文件上传到此处。问题是,每当我对一个新版本进行排队时,这个文件夹就会被破坏,所有指向媒体的链接都不会指向任何东西。我在管理和设置 TFS 方面相当陌生,所以我想知道每当我对新构建进行排队时,是否有任何方法可以保留我的媒体文件夹的内容。有任何想法吗?
根据您的描述,构建代理中有工作目录的概念。如果您在构建定义中 set clean=true ,这将在您查询新构建时删除以前的构建输出。不确定您的媒体文件夹位于何处,请避免将其 create/put 放在构建代理的某些目录中,例如 Build.ArtifactStagingDirectory
The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent_work\a.
A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts steps.
Note: This directory is purged before each new build, so you don't have to clean it up yourself.
更多关于build/release中文件夹路径的详细信息,您可以参考这个教程--Predefined variables
好的,所以我花了一整天的时间看着这个。
在我的 C# 代码中,我创建了一个目录,如下所示:
// -- Create a new file name that is unique
string fileExtension = Path.GetExtension(upload.FileName);
Guid fileGuid = Guid.NewGuid();
string fileName = fileGuid + fileExtension;
// -- Create the directory and upload the image to that directory
string mediaDirectory = Server.MapPath("~/Media/");
Directory.CreateDirectory(mediaDirectory);
string filePath = Path.Combine(mediaDirectory, fileName);
upload.SaveAs(filePath);
然后我会在媒体对象上设置图像 url,例如:
string imageUrl = "/Media/" + fileName;
所以现在,我没有将图像存储在数据库中,而是将 URL 存储到图像中。
这是在我可以存储文件的应用程序目录中创建的目录:
这很酷,但正如我提到的,每次我对新构建进行排队时,这个目录都会被销毁。我解决这个问题的方法是修改我存储图像的位置:
// -- Create a new file name that is unique
string fileExtension = Path.GetExtension(upload.FileName);
Guid fileGuid = Guid.NewGuid();
string fileName = fileGuid + fileExtension;
// -- Create the directory and upload the image to that directory
// The Media directory will be created on the C drive root
string mediaDirectory = @"c:\Media";
Directory.CreateDirectory(mediaDirectory);
string filePath = Path.Combine(mediaDirectory, fileName);
upload.SaveAs(filePath);
现在,我的 Media 文件夹已创建在服务器的 C 驱动器上,并且不会在我对新构建进行排队时被破坏。由于该应用程序无法访问应用程序目录之外的文件,因此我需要一种方法来访问 Media 目录中的这些文件。我所做的是在 IIS 中创建一个指向 Media 文件夹的新虚拟文件夹,并为其指定别名 Media:
现在我可以访问我放在 Media 目录中的所有文件,并在需要时正确显示图像。我真的希望这对某人有帮助,因为我花了太长时间看这个。